
- 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:07 AM
What was the issue with business rule?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:18 AM
I created an 'After' business rule that runs on Update. Below is the code:
(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.');
return false;
}
})(current, previous);
The issue here is I would like the operation to be aborted if there is no time worked, but the operation is still going through. Ideally we'd also like an alert (not error message) to appear immediately, but I only know how to do this using client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:20 AM
Try your script as a Before script ( the update will have already occurred in the after script ).
You might also have code like the following if you abort the update:
gs.addErrorMessage("Your error to the user goes here.");
current.setAbortAction(true);
EDIT:
Taylor, if you find that your problem is solved by using a before BR and the setabortaction command, please ,mark Abhinay's answer as correct since his advice is more specific to your situation than mine.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2017 07:47 AM
Thanks for the reply Steve, that worked like a charm