Best way to ensure Time Worked is entered every time user Updates a Task?

tslogue
Tera Contributor

I asked a similar question to this earlier this month:How do I validate that Time Worked is being entered for each Task Update?

The solution we implemented was a 'Before' business rule on the Task table that, on update, calculates whether time worked was entered, and aborts the update action while displaying an error message asking for time to be entered. Below is the code of that Business Rule:

(function executeRule(current, previous /*null when async*/) {

var start = previous.time_worked.dateNumericValue();

  var end = current.time_worked.dateNumericValue();

  var diff = end - start;

  if (diff == 0){

  gs.addErrorMessage('Please enter Time Worked before updating Tasks.');

  current.setAbortAction(true);

  }

})(current, previous);

The above solution that we tried implementing (in our dev environment) has caused more issues than we anticipated.The issues arise when a user updates a Task, and that update causes updates to other Tasks. While the initial update to the user's Task may have time worked entered, if that Task update causes another Task to update (with no time entered), the update operation of the 'other' task is aborted and an error message is still being displayed. We only want to mandate Time Worked entry on the Task that is directly being updated by our user, not any other Task updates that may occur as a result of our initial Task update.

Does anyone know how to limit a business rule to only run on Tasks that have been directly updated by the User, and no other Task updates that may have been caused by the initial update? Or maybe someone knows how to capture the time that has been entered into a Timer (not the accumulated amount, but just the amount that is being entered currently? This would at least allow me to figure out if time is being entered without running a business rule calculation.

Any help would be appreciated. Thanks!

7 REPLIES 7

Our display business rule script is very simple. It just captures time worked and sets a g_scratchpad variable to the value of time worked before the form is opened :



(function executeRule(current, previous /*null when async*/) {



  g_scratchpad.time_worked_inc = current.time_worked.dateNumericValue();


  ///gs.log('time: '+ current.time_worked.dateNumericValue(),'time');



})(current, previous);




Here is the onSubmit Client Script. We have it only running on certain action types (when someone saves or updates):


function onSubmit() {



  ///get the value of time worked as the user tries to update/save thee form


  var timer = g_form.getIntValue('time_worked');



  //multiply time worked integer value by 1000


  var dateNumeric = timer * 1000;



  //get the name of the action the user is performing, we only want to prevent someone from updating or saving if there is not time worked


  var action = g_form.getActionName();



  //if the user's action is update or save, make sure they entered time worked, and if not, prompt an alert message


  if (action == 'sysverb_update' || action == 'sysverb_update_and_stay'){


  var diff = dateNumeric - g_scratchpad.time_worked_inc;


  if(diff == 0){


  alert('Please enter Time Worked before updating Incidents. Thank You.');


  return false;


  }


  }


}


Hi Tslogue,

Our organization have the same issue and I am tasked with finding a solution. A review of what you did seem to be what I am looking for. If you dont mind can you share the codes you used and any lessons learnt along the way?

 

Thank you

Garfield

 

tslogue
Tera Contributor

Hey Garfield -

My post on â€Ž06-21-2017 at 9:32am pretty much sums up the solution we developed. It has 2 parts that work together. First, a display business rule that runs on insert and update. The business rule just captures time worked and sets a g_scratchpad variable to the value of time worked before the form is opened. The script for that business rule is below. You will need this business rule on the Task table (or whatever task types you want to make time worked mandatory):

(function executeRule(current, previous /*null when async*/) {

  g_scratchpad.time_worked_inc = current.time_worked.dateNumericValue();

  ///gs.log('time: '+ current.time_worked.dateNumericValue(),'time');

})(current, previous);

 

The second part is an onSubmit client script that checks to see if there was any time entered and throws an alert message if not. You’ll either need one of these on your Task table or on the specific task types you want time worked to be mandatory on. Below is the onSubmit Client Script. We have it only running on certain action types (when someone saves or updates). There are other actions people can take on forms that are not save or update, and we only want to check if they entered time when they’re saving or updating the form:



function onSubmit() {



  ///get the value of time worked as the user tries to update/save thee form

 

  var timer = g_form.getIntValue('time_worked');



  //multiply time worked integer value by 1000

 

  var dateNumeric = timer * 1000;



  //get the name of the action the user is performing, we only want to prevent someone from updating or saving if there is not time worked

 

  var action = g_form.getActionName();

 

  //if the user's action is update or save, make sure they entered time worked, and if not, prompt an alert message

 

  if (action == 'sysverb_update' || action == 'sysverb_update_and_stay'){

 

  var diff = dateNumeric - g_scratchpad.time_worked_inc;

 

  if(diff == 0){

  alert('Please enter Time Worked before updating Incidents. Thank You.');

  return false;

  }

 

The only real lesson learned that i can share is that this was a temporary solution for our organization. It was in place for a year or two and then we deactivated it as the organization evolved. It worked well for us at the time. I'd just make sure to only place it on the task tables that you are targeting to be mandatory. If you put it on the core Task table you might be surprised how many tables extend it where you don't care about time worked, and will have to go back and add exceptions.

Let me know if you have further questions.

Thanks,
Taylor