- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 06:50 AM
I'm attempting to set a "start date" date/time field to the current date/time based upon the criteria that one field is true, and the "start date" field is empty. I've been able to make it set the date/time initially (that part works perfectly); however, every time I send a new update, it changes the date to the current time, even though the "start date" field is populated. I've done an exhaustive search, and can find nothing that remediates this. Help!
I'm sure I'm missing something simple. This is the relevant code:
__________
When: Before, on Insert or Update
I've done this with and without filter conditions: Send to Legal is true, Legal start date is empty
_________
(function executeRule(current, previous /*null when async*/) {
if (current.send_to_legal=='true' && (!current.legal_start_date.nil())) {
current.legal_start_date = gs.nowDateTime();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 06:59 AM
You can do this with condition on the BR so it only runs if it's empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 06:59 AM
Make sure that the if cindition is satisfied, and try using this line instead
current.legal_start_date = new GlideDateTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 06:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 06:59 AM
Hi,
Should be a before business rule and you can literally use the conditions there, instead of scripting that, for it to fire on "Update".
Plus you're also saying not nil....with that line.
So something like:
Then under actions, you can have that one line: current.legal_start_date = gs.nowDateTime();
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2018 07:00 AM