Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using Business Rule and Script Action to Update a field

Vamsi26
Tera Contributor

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

Vamsi26_0-1718031924007.png

 

2. Script Action Mapped with Event

 

Vamsi26_1-1718031978661.png

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.

Vamsi26_2-1718032412610.png

 

Vamsi26_3-1718032433434.png

 

It's not working. 

 

 

 

1 REPLY 1

Community Alums
Not applicable

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