Using Business Rule and Script Action to Update a field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 08:21 AM
Hi everyone,
I have a requirement to change the state field to "Awaiting" if due date is past by 15days.
So for that I created the Event, Script Action and Business Rule. It's not working.
The following things i used.
1. Event has created
2. Script Action Mapped with Event
3. Business rule Called the script action event into Business Rule.
When to run after update
due relative after 15days(giving as 5mins for testing purpose). Scheduled a Event and checking if due date changes what if my previous due date changes deleting the event queued already.
It's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 08:57 AM
Hi @Vamsi26 ,
Looks like there is an issue with the BR for the scheduled event-
Here is an updated code, please try it-
(function executeRule(current, previous /*null when async*/) {
if (current.due_date != previous.due_date) {
// Delete any previously scheduled events for this record
var grEvent = new GlideRecord('sysevent');
grEvent.addQuery('name', 'Enhancement.Due.Date');
grEvent.addQuery('instance', current.sys_id);
grEvent.query();
grEvent.deleteMultiple();
// Schedule the new event
var dueDate = new GlideDateTime(current.due_date.getDisplayValue());
gs.eventQueueScheduled('Enhancement.Due.Date', current, '', '', dueDate);
}
})(current, previous);
Rest of the configs look fine, try to put some logs to check the values being passed and set.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar