The Zurich release has arrived! Interested in new features and functionalities? Click here for more

need a way to stop time worked on new records

moserism
Kilo Contributor

My users are complaining that when they create a new record, such as a scrum task, the time worked timer is started by default. Thus, they are getting very small increments of time logged to items that they have only created a record for, but not worked on. Is there a way to disable the timer from starting automatically when a new record is created?

4 REPLIES 4

ark6
Mega Guru

Hi Michael,



Please try the below code in an onload client script. In my case,table selected is incident and type is onload



function onLoad() {


  if(g_form.isNewRecord()){


      if(g_form.getElement('time_worked')){


              toggleTimer('time_worked','00:00:00');


      }


}




function toggleTimer(fieldName,timerVal){


      try{


              //Get the necessary timer elements for fieldName given


              var timerEl = $('element.' + g_form.tableName + '.' + fieldName);


              if (timerEl != null){


                      //Make sure script does not break if field not present


                      var timerPause = timerEl.select('input[id*=paused]')[0];


                      var timerImg = timerEl.select('img[src*=images/timer_]')[0];


                     


                      //Toggle the timer


                      if(timerPause.value == 'false'){


                              timerPause.value = 'true';


                                var timerIcon = $('link.' + g_form.tableName + '.' + fieldName);


                                timerIcon.removeClassName('icon-stop');


                                timerIcon.addClassName('icon-play');


                                //Change any title tags


                              timerIcon.setAttribute('data-original-title', 'Start Timer');


                      }


                      else{


                              timerPause.value = 'false';


                                var timerIcon = $('link.' + g_form.tableName + '.' + fieldName);


                                timerIcon.removeClassName('icon-play');


                                timerIcon.addClassName('icon-stop');


                                //Change any title tags


                              timerIcon.setAttribute('data-original-title', 'Pause Timer');


                      }


                      //Reset the timer to timerVal given


                      if(timerVal){


                              g_form.setValue(fieldName,timerVal);


                      }


              }


      }catch(e){}


}


}


ash36
Kilo Contributor

I have used this on Task table and made it inherited. You can use on any table of your choice without any change in the code.


  1. function onLoad() {  
  2.       if(g_form.getElement('time_worked')){  
  3.               pauseTimer('time_worked');  
  4.       }  
  5. }  
  6.  
  7.  
  8. function pauseTimer(fieldName){  
  9.       try{  
  10.               //Get the necessary timer elements for fieldName given  
  11.               var timerEl = $('element.' + g_form.tableName + '.' + fieldName);  
  12.               if (timerEl != null){  
  13.                       //Make sure script does not break if field not present  
  14.                       var timerPause = timerEl.select('input[id*=paused]')[0];  
  15.                       var timerImg = timerEl.select('img[src*=images/timer_]')[0];  
  16.                          
  17.                       //Toggle the timer  
  18.                       if(timerPause.value == 'false'){  
  19.                               timerPause.value = 'true';  
  20.                               if(timerImg){  
  21.                                       timerImg.src = 'images/timer_start.gifx';  
  22.                               }  
  23.                               else{  
  24.                                       //UI15 styling compatibility  
  25.                                       var timerIcon = $('link.' + g_form.tableName + '.' + fieldName);  
  26.                                       timerIcon.removeClassName('icon-stop');  
  27.                                       timerIcon.addClassName('icon-play');  
  28.                               }  
  29.                       }  
  30.                       //Reset the timer to 0  
  31.                       g_form.setValue(fieldName,'00:00:00');  
  32.  
  33.  
  34.               }  
  35.       }catch(e){}  
  36. }  

sniega1
Tera Contributor

Hello,


this doesn't work like it should, time is not stopped each time we update form but it is just set to 00.00.00


It there any other solution?



Regards


Sniega


ash36
Kilo Contributor

Comment out line #31