Using Timer control to time how long a form is open

  • 13 July 2017
  • 1 reply
  • 106 views

Badge +8

In reference to the timer control in this article:

 

https://help.k2.com/onlinehelp/k2appit/userguide/current/default.htm#timer_control.htm

 

it states that "The Timer control can be used for example to keep track of the time spent on a specific Form, i.e. counting the seconds lapsed once the Form is run."

 

It then goes on to provide little to no help on exactly how to do this.

 

What I'd like to do is have the timer control start when a subform initializes and then stop when the subform closes and store the number of "ticks" (even better, the number of seconds" in a parameter or datafield that I can then write back to the database with the amount of seconds the form was open total.  

 

So, I'm thinking you'd have a rule to execute the timer's start method when the form initializes...and run the timer's stop method when the subform closes...but does anyone have any idea how you could have the number of ticks (or preferable seconds) record somewhere that can be written back also at the time the subform closes?  I expect I'll need to have a datafield or two and an operation within that datafield to add up the number of ticks...but I'm not seeing how to do it.

 

Help is appreciated.  


1 reply

Badge +15

Hi,


  


I am not sure if the Timer control is the best solution for this. Why not calculate the time difference yourself?


 


1. Set up three data label, set its type to 'Time'. One is for storing start time, the second one is for storing end time, and the last one is for calculating the difference.


 


2. When form initalize, use the 'Transfer Data' rule to set the current time to the first data label


 


3. When you want to end the time recording, use 'Transfer Data' rule again to set current time to the second data label


 


4. For the last data label, set an expression, and use the Date/Time Difference operator, so that it looks something like this:


 




Reply