Michael Fry1
Kilo Patron

The use case is simple. If there is an update to a [record], send a notification with the previous values and the new values.

 

First, if you didn’t realize, Flow trigger execution tracks which fields have changed.

MichaelFry1_0-1753813321206.png

 

 

Below shows the output from above. The changed fields data is stored in an Array. This example shows one field changed (from a change request record). You can see the previous value and the new value of the field “state”. If it was a reference field, current_value and possible previous_value would show as sysIDs.

{

    "Changed Fields": [

        {

            "current_display_value": "Authorize",

            "current_value": "-3",

            "field_name": "state",

            "previous_display_value": "Assess",

            "previous_value": "-4"

        }

    ]

}

 

Second, how do I get that data and use it in an email?

Others have shared solutions that check for a specific field change—like sending a notification if the Short Description changes. But what happens if multiple fields are updated at once? Using a "For Each" loop on the changed fields array might give you the needed data, but it could lead to multiple notifications—one for each field change—which isn’t practical.

In my scenario, the email notification depended on changes to four specific fields. To handle this, I created four Flow variables, one for each field, and then used a script step to assign either the current value or the previous value, depending on whether the field had changed. Let me walk you through how I did it.

Field

Current value

Previous value

Assigned to

Mike

Joe

Status

Hold

In progress

Business App

Visio

Visio

 

In the script (posted below) for each flow variable, I check if the field (e.g., Assigned To) is in the list of changed fields. If it's not, the variable is set to the current value (e.g., Mike). But if the field is found in the changed fields, I set the variable to the previous value (e.g., Joe).

This way, when sending the email using the Send Email flow action, I can reference:

  • The flow variable for the previous value, and
  • The trigger record for the current value.

This approach ensures that only one email is sent, with clear context about what changed.

 

Here is my code:

//get the data from changed field output

var changedArray = fd_data.trigger.changed_fields;

//get the current value for the field I need

var output = fd_data.trigger.current.assigned_to;

for (var i = 0; i < changedArray.length; i++) {

//if you find assigned to in the changedArray   

if (changedArray[i].field_name == ‘assigned_to’) {

        // get the previous value

        output = changedArray[i].previous_display_value;

    }

}

return output;

 

Does anyone else have a different solution?

I hope this helps someone else!

Thanks for reading.

4 Comments