From a Select action in Power Automate, I get a "Project Crew" array as an output. This array contains Resources. Every Resource has a LabotType and Units.
Here is an example of a Project Crew that has 3 Resources (but 4 units in total):
From another Select action I get an array of "Crew Templates". Each Crew Template has an ID and an array of Resources, where here as well - every Resource has a labor type and Units. In this object, these properties are named _dkt_labortype_value and dkt_units.
Here is an example of an array of two Crew Templates, each has two Resources.
I need to check which of the Crew Templates are included in the Project Crew.
Note, even if the Project Crew has other Resources on top of the Crew Template's Resources, this is still a match. As long as all Crew Template's Resources exist in the Project Crew (the order doesn't matter), with the same number of Units, then this is a match, and I want to return the associated Crew Template ID.
In the example above, the second Crew Template is my winner, because both its Resources (2 Units of Labor Type/_dkt_labortype_value = ed0f66ec-4d3a-ef11-8409-000d3a580b08, and 1 Units of Labor Type/_dkt_labortype_value = 581dc2ac-427b-ef11-a671-6045bdd755fb) existin the Project Crew.
Challenges:
I'm trying to avoid Apply to each.
The arrays to compare are within another array.
The properties are not named the same between both arrays. I couldn't solve that with Select because the arrays are inside another array.
If you can guide me how to solve it either with Select to choose just the data I want from the second array of arrays, or to use XML/XPATH to manipulate it... or any other efficient idea that will not involve apply to each it will be greatly appreciated.
I have found the way to solve it with one apply to each, on the Crew Templates array (note: In my flow, Production Defaults = Crew Template).
For every Crew Template, I shape all Resources to have the same shape as the Project Crew Resource. Then, I filter the Crew Template for Resources that are not included in the Project Crew. If the result is zero, that means that all Crew Template Resources are included in the Project Crew, therefore this is the Crew Template that I'm looking for.
I'm still looking for a more efficient way of doing this, that will not involve an Apply to each.
Thanks,
Gil.
Was this reply helpful?YesNo
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.