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

MaxMixali
Kilo Sage

Pass Previous Values as Flow Inputs

In your Business Rule, explicitly pass the previous values as input variables to the flow:

Business Rule (Before/After Update):

 
 
javascript
(function executeRule(current, previous /*null when async*/) {
    
    // Store previous values in an object
    var previousValues = {
        state: previous.state.toString(),
        assigned_to: previous.assigned_to.toString(),
        priority: previous.priority.toString()
        // Add other fields you need
    };
    
    // Trigger the flow with both current and previous values
    var inputs = {
        current_record: current.getUniqueValue(),
        table_name: current.getTableName(),
        previous_state: previousValues.state,
        previous_assigned_to: previousValues.assigned_to,
        previous_priority: previousValues.priority
    };
    
    sn_fd.FlowAPI.getRunner().trigger('your_flow_sys_id', inputs);
    
})(current, previous);

Then in your Flow Designer script action, access these as input variables:

 
 
javascript
inputs.previous_state
inputs.previous_assigned_to



Hello i hope that can help

If you find this answer useful, please mark it as solution accepted/helpful

Massimiliano Micali