Use Filter Array instead of Nested List Records to Optimise the Cloud Flow
In this post, I will explain how you can
use the Filter Array action
to filter the required rows of the output data from the
List Records action.
When there is a requirement to match the rows from two arrays using a
particular property value, you can use the Filter Array action to
get the matching object from the array. In the scenario below, you will
see how it can be used to get the matching row from the List Records action
output based on the value of the current row.
Scenario
To demonstrate the capability of the Filter Array, I will use the Opportunity, Opportunity Line, Quote, Quote Line and Product tables within Dynamics 365 Sales.
When creating an Opportunity Line for an Opportunity, Users can manually enter the Manual Discount for each Opportunity Line. A Quote can also be created from an Opportunity which copies the value of the Manual Discount from the respective Opportunity Lines when creating the related Quotes Line.
The requirement for our scenario today is "When the Manual Discount in an Opportunity Line is updated and the user checks the flag to refresh the data, the system must update the respective Quote Lines with the new value of Manual Discount from Opportunity Lines. Now that is going to be a challenge as there is no direct connection between the Opportunity Line and the Quote Line as you can see in the Entity Relationship Diagram below.
To
get the Manual Discount value from the Opportunity Line row, the Existing Product can be used the match and get the corresponding Quote Line. The assumption for this scenario is that there will not be more than one Opportunity Line for each Product. If there can be multiple Opportunity Lines with the same Product, the values of multiple columns need to be matched to get the rows. But for the sake of simplicity in this scenario, let's assume that all Opportunity Line rows have a unique product. Let's see
how you can easily get the corresponding Opportunity Line row using
another List Records action.Nested List Records to Retrieve Matching Row
Filter Array to Retrieve Matching Row
The output of the Filter array step is also an array which is the subset of the main array with values matching the criteria. In this scenario, there is only one Opportunity Line that matches with the Existing Product value, so let's use first() to get the value without another Apply to each loop.
Summary
By using the Filter Array action we can the output data from the List Records action to get specific rows and by doing so, we can query all data at once and filter to reduce the number of server-side calls. Even though it can improve the performance of the flow, the flow author will require a little bit of knowledge of writing an expression to use the Filter Array action.
Comments
Post a Comment