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

Michael Fry1
Kilo Patron

Can't you just have the Time Worked timer start automatically? Then time would always get entered.


Vamsi Saladi
Tera Contributor

make time worked mandatory. Create a u_previous_time_worked field and hide it from form. when insert/update always (user BRule) copy time_worked to u_previous_time worked.
now when u have both previous and current times on form. so use same difference code you used onsubmit client script to send an alert and stop submission.



and you can just have timer run automatically when page opens so before user clicks stop atleast a couple of seconds may have been recorded.


system properties -> ui properties -> Task timer field automatically starts when the task is displayed ->true


Thank you for the reply Vamsi. Looking at your solution it looks like it would definitely work for what we were trying to do. This is what we ended up doing for our solution:



Created a 'Display' business rule and onSubmit Client Script on each table we wanted time worked to be mandatory on. The Display business rule captures time worked on form open. Using g_scratchpad functionality, we passed the value of time worked on open to an onSubmit client script. The onSubmit client script captures the original time worked using g_scratchpad, compares it to the original time worked, and prevents submission if time didn't increment by more than 0.



I can post the code if someone is interested.


ya pls post it i can use as reference.
thank you.