The CreatorCon Call for Content is officially open! Get started here.

How do I validate that Time Worked is being entered for each Task Update?

tslogue
Tera Contributor

We have a unique requirement that I can't seem to figure out a solution for, any ideas are welcome!

Our company would like to make the 'Time Worked' field on the Task table mandatory. Not just Mandatory in the sense that a value must be present in the field for an update to take place (this is easy, check the mandatory box on the field dictionary), but mandatory in the sense that Time Worked must be incremented at least one second before you can update a Task.

I've tried this using a business rule because it has 'previous' and 'current' which will allow me to calculate the difference in the Time Worked for each update, but the business rule doesn't provide me with the hard stop that an alert from a client script will give me. The problem with using a client script is that I can't calculate the previous time worked compared to the current time worked, so there is no easy way to see if the Timer is going to increment before the update occurs.

Is there a way to access the time that is being incremented in a Timer field before the time is added to the Task Time Worked table? Or maybe there is a way to use a Client Script or Script include and AJAX to perform the calculation of time worked prior to the update taking place?

1 ACCEPTED SOLUTION

It should be a before business rule and you cannot use return false in business rule. You need to setAbortACtion to stop the record update . Use this



  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);


  }


View solution in original post

7 REPLIES 7

It should be a before business rule and you cannot use return false in business rule. You need to setAbortACtion to stop the record update . Use this



  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);


  }


Thanks for the help Abhinay,



Below is the working code after changing it to a 'Before' 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);


Abhinay Erra
Giga Sage

Glad you got this working