How to add a timer to the SalesTable form

When you want a grid in a form to be updated on a regular basis (so your users always see latest information), you need to add a timer to your form. You need two things. A timer method and a initial call to it when the form starts.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// START 071212 FourOne/HL (Project_A)
void FO_UpdateIdleTime()
{
    #define.SECOND(1000) // one second in millisec.
    ;
    // this line calls refresh on the header, change to true 
    // if you want to include also lines.
    this.doRefresh(false);
 
    // Set a TimeOut with the idle flag set to True
    this.setTimeOut(identifierstr(FO_UpdateIdleTime), 
                          20 * #SECOND, true);
}
// END 071212 FourOne/HL (Project_A)

If last parameter to setTimeOut() method is set to true, it will start count when the users havent touched the mouse or keyboard for the specified time.

Second, in the Init() method to the SalesTable form, you need to add first call.

1
2
3
   // START 071212 FourOne/HL (Project_A)
   this.FO_UpdateIdleTime();
   // END 071212 FourOne/HL (Project_A)

There is a backside to this. If the user input something, let the cursor stay in the same field (so the line does NOT get saved back to the db) and wait. When the Idle method does refresh after your specified delay, the user input is lost. If you want to, you can add a popup question to handle this. Here we only present how you could have a background method waiting for a specified time. Always count, or like this, only when the keyboard/mouse is idle (untoched for a period of time).

Last 5 posts in Development

One thought on “How to add a timer to the SalesTable form

Leave a Reply

Your email address will not be published. Required fields are marked *