
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 06:56 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:24 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:24 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:48 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 08:00 AM
Glad you got this working