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.

How to pass previous values from business rules to script action in servicenow

18wj1a05d2
Kilo Contributor

I am unable to pass previous values to script action from Business Rules. could you please help me.

 

Many thanks,

Raghuveer

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Post your attempt.  Have you logged the previous value in the Business Rule to ensure it is captured correctly before looking for it elsewhere?

Renat Akhmedov
Kilo Sage

Hi @18wj1a05d2

You can pass previous values from a Business Rule into a Script Action, but not automatically - you must pass them explicitly using Event parameters. A script action only receives the values that you send through the gs.eventQueue() call.

Best regards,
Renat Akhmedov

Ankur Bawiskar
Tera Patron
Tera Patron

@18wj1a05d2 

yes it's possible to send via event parm1 or event parm2

something like this

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    gs.eventQueue('eventName', current.state, previous.state);

})(current, previous);

Then in script action you can grab this

var currentValue = event.parm1;
var previousValue = event.parm2;

An Examination of gs.eventQueue 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

M Iftikhar
Tera Sage

Hi @18wj1a05d2 ,
To pass previous values from a Business Rule to a Script Action, you must send them through event parameters, because Script Actions cannot access previous directly.

Business Rule

gs.eventQueue(
  'your.custom.event',
  current,
  current.your_field,      // param1
  previous.your_field      // param2
);

Script Action

var currentValue = event.parm1;
var previousValue = event.parm2;

Script Action now receives both current and previous values.

If my response helped, please mark it as the accepted solution so others can benefit as well. 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.