How to get the previous value of a field using Flow Designer if approval is rejected

matthew_hughes
Kilo Sage

I'm working on a flow where a the Record Condition of a Business Application gets set to 'BIA Approval' when a user clicks on a UI Action. 

 

 

matthew_hughes_0-1739287782951.png

When the Business Application is set to 'BIA Approval', it generates approvals. However, what I'm wanting to do is set the value of the Record Condition field on the Business Application back to it's previous value if the approval is rejected. In the above scenario, it should be set back to Complete when rejected. I've tried using the following code, but it doesn't work:

matthew_hughes_1-1739287941661.png

 

So I was just wondering if anybody knows what I need to do to set the 'Record Condition' to it's previous value when rejected by approvals.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

If your trigger record is the business application, you should have values populated in the 'changed fields' pill

var changedFields = fd_data.trigger.changed_fields;
var targetField = 'YOUR_FIELD_HERE';
var changedFieldObj = changedFields.find(function(field){
    return field.field_name == targetField;
})

if(changedFieldObj && changedFieldObj.hasOwnProperty('previous_value')){
    return changedFieldObj.previous_value
}

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

you won't get previous value using that syntax using fd_data

1) create a flow variable and store the current value before the update

2) then use it in later stage

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@matthew_hughes 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Kieran Anson
Kilo Patron

Hi,

If your trigger record is the business application, you should have values populated in the 'changed fields' pill

var changedFields = fd_data.trigger.changed_fields;
var targetField = 'YOUR_FIELD_HERE';
var changedFieldObj = changedFields.find(function(field){
    return field.field_name == targetField;
})

if(changedFieldObj && changedFieldObj.hasOwnProperty('previous_value')){
    return changedFieldObj.previous_value
}