compare old values and new values in flow designer

mariavic1998
Tera Contributor

Hello everyone, I wanted to know if you have any idea of how to approach this condition in flow designer, I think there's some scripting needed but I'm not sure. the conditional is the following one: 

mariavic1998_2-1708976431930.png

 

and this is all I have until now:

mariavic1998_1-1708976191009.png

 

1 ACCEPTED SOLUTION

CMDB Whisperer
Mega Sage
Mega Sage

The only direct access you have to the previous value is from within a Business Rule, not a flow.  The flow is something that runs asynchronously, after a record has already been updated, so the previous value is no longer available to the program/flow logic.  So you are best off accomplishing this logic in a Business Rule. 

That said, if you absolutely need to do this from a flow after the update is already made, you may be able to pass the values to an Event that could then trigger a Flow.


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.

View solution in original post

5 REPLIES 5

CMDB Whisperer
Mega Sage
Mega Sage

The only direct access you have to the previous value is from within a Business Rule, not a flow.  The flow is something that runs asynchronously, after a record has already been updated, so the previous value is no longer available to the program/flow logic.  So you are best off accomplishing this logic in a Business Rule. 

That said, if you absolutely need to do this from a flow after the update is already made, you may be able to pass the values to an Event that could then trigger a Flow.


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.

Thank you Paul!

Sumanth16
Kilo Patron

Hi @mariavic1998 ,

 

ServiceNow stores most changes in the sys_audit table you can go there to get all previous values if needed.
A fair warning though, the sys_audit table is huge, so don't go down this path if not absolutely necessary.

Now to the solution;
Create a Subflow that takes input parameters on which table, field name, record sysid, and created by.
The subflow itself will be simple, it does a look up on the audit table, using supplied input parameters to get the result, and returns the "oldvalue" value.

Then call on that subflow from whatever Flow that uses the trigger "Record updated".

 

Please refer to below threads:

https://www.servicenow.com/community/developer-articles/how-to-get-previous-values-using-flow-design...

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0855770

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

That "fair warning" is not strong enough.  Querying the sys_audit table is an extremely bad idea.  Even if you have a very specific query, it can take hours or even days for a single query to complete, depending on the size of your table.  Rather than unnecessarily looking up the value from the flow, I would strongly recommend considering the approach of using a business rule, which provides you both the current and previous values, and if you need to pass this to a Flow, then simply fire an Event with both the current and previous values as parameters of the Event, and then to handle the Event run a script to start a Flow using the parameters.  


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.