See an updated version of this post here: Let’s Revisit How to use both the Selected and the Edited records in a Datatable
My Datatable Flow Screen Component allows a user to both Select records and make Edits to records. The component returns two separate collection variables. One of them includes the original values of just the selected records. The other one includes just the edited records whether they were selected or not.
Sometimes, you may want to process just the selected records in your flow, but include the edited values in those selected records. This sample flow shows how you can create a selected record collection with edits. The flow loops through each of the selected records and if no edits were made to it, it gets added to the final collection. If an edited version of the record is available, it gets added to the final collection instead.
Here’s the Select & Edit Screen Datatable displaying all of the Product records from an Opportunity.
I’ll select 3 records and make edits to 2 of them.
My final results show the 3 selected records with the edited fields included.
Let’s go through the steps you can follow to combine the outputs from the Datatable component. In this section, I’ll show you how each of the nodes in the flow is configured.
I start with an Opportunity record with an Id that is passed into the flow. Whenever possible, let the flow Automatically store all field values.
All of the Opportunity Products are added to a Collection (OpportunityLineItem).
Because I am displaying a similar Datatable multiple times in this flow, I store my attributes in variables so they can be reused for each Datatable.
The Datatable is displayed using the attributes assigned earlier. Here, the user can select and edit records.
I am manually assigning the outputs from the Datatable to new collection variables to make the steps in this flow more readable.
This loop will take us through each of the records in the collection of Selected records where we will perform the next few steps on each record. New in Summer ‘20, the flow will automatically create a loop variable for you.
In this step, I look for a record in the collection of Edited records with the same Id as the current Selected record in the loop. The “Find Records In Collection” Flow Action is part of a group of very powerful actions you can include in your flows to act on record collections. The entire group can be found and installed from here.
The output from the Flow Action will be the matching record from the collection of Edited records if found, otherwise it will return a null value. This Decision checks to see if that record was found.
When an Edited record is found, it is added to the final collection variable that we will be using for the rest of our flow.
When there is no matching Edited record, we use the Selected record from the Loop instead.
Whichever record we chose now gets added to the final collection variable.
After the end of the Loop, I display another Datatable with the values from the final collection variable. This is just an example. In your own flow you may be doing something here like adding updated products to a new renewal Opportunity or something else with the selected and edited records.
Collection Actions for Flow
Sample Flow (Install in Sandbox)
This includes DatatableV2 and FindRecordsInCollection