- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:09 AM
Hi Team,
I have a date field on a record producer, and what I would like to achieve is to set the due date on the created ticket 5 days before the date field on the record producer.
I attempted this through a business rule script -
(function executeRule(current, previous /*null when async*/) {
var sd = new GlideDateTime();
sd.setValue('rec_prod_field_name');
sd.addDaysUTC(-5);
current.due_date=sd.getDisplayValue();
})(current, previous);
Can someone please advise the best way to do this and how?!
Thanks,
Alex
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:29 AM
Hi
You can try the below Code :
(function executeRule(current, previous /*null when async*/) {
var sd = new GlideDateTime(current.variables.date_variable_name); //Write down Variable name instead of 'date_variable_name' from record producer.
sd.addDaysUTC(-5);
current.due_date=sd.getDisplayValue();
})(current, previous);
Please mark my answer as Correct/Helpful based on impact.
Regards,
Gunjan Kiratkar
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:22 AM
You can't access record producer variables directly in BR, you will have to glide into question_answer table to get value. so instead you can use below script in record producer script section, that will be easy solution for you
var sd = new GlideDateTime(producer.rec_prod_field_name);
sd.addDaysUTC(-5);
current.due_date=sd.getDisplayValue(); OR current.due_date=sd;
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:28 AM
Instead of writing new BR, you can do above in record producer script.
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:25 AM
Or for referencing variables on a record producer, you would make a minor change to the above:
var sd = new GlideDateTime(producer.rec_prod_field_name);
sd.addDaysUTC(-5);
current.due_date = sd.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2022 05:29 AM
Hi
You can try the below Code :
(function executeRule(current, previous /*null when async*/) {
var sd = new GlideDateTime(current.variables.date_variable_name); //Write down Variable name instead of 'date_variable_name' from record producer.
sd.addDaysUTC(-5);
current.due_date=sd.getDisplayValue();
})(current, previous);
Please mark my answer as Correct/Helpful based on impact.
Regards,
Gunjan Kiratkar