cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Derek4
Resolver I
Resolver I

Store all data in array and retrieve only needed data

Hi All,

 

I'm building a simple approval flow for an CDS entity, and I need to update the some fields of the CDS entity from approver's comment, approval and date, I have create three array variables for them:

微信截图_20210222112047.png

 

The problem is there are total 6 approvers and by flow they all need to approve twice (one before the action done, one after it) and I need to record all their comments, approvals and dates and update the corresponding fields of the CDS entity.

 

I could create one variable for each input (total 36 variables) and I think that's really stupid, so is there a way that I can store all the approver's input in the three variables I created and retrieve the corresponding data to update the fields?

 

Thanks in advance!

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hello @Derek4 ,

if you need to update a specific columns for specific approvers, then the arrays solution gets quite complex (and I don't know right now how I'd solve it).

I think in such situation it might be better to run the approvals in parallel branches, each role it's own parallel branch and after the approval update the respective columns in the item, e.g. one brach is 'Manager' task -> 'Assign a task and wait for response' from that manager and then update the 'Manager' columns. The same in all the other parallel branches for the other approvers. If you update the columns right after the approval, you won't even need variables.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Hello @Derek4 ,

if there's only 1 user per approval action then you can leave the 'Apply to each' there. With one approver it'll have only a single response to process = 1 run of the loop.

First(...) expression expects the array with 'Responses' as the parameter, only after you select the first item from the array you can access the specific content of that response, e.g. expression to get directly display name of the approving user would look like this:

first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['responder/displayName']

Get the first(...) item from the 'Responses' output from the 'Start and wait for an approval' and take the 'Responses approval name'.

But I think it's totally fine to keep the 'Apply to each' in the flow.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

5 REPLIES 5
tom_riha
Super User
Super User

Hello @Derek4 ,

I think that if you created the 3 variables as an array variables, you could append the results into them, and by the end of the process loop through them to retrieve the approval data.

Variable 1 with array of approvers, variable 2 with array of comments and variable 3 with array of dates. If you append to them at the same time then value on index 0 in all the variables should be one approval step, value on index 1 the second approval step etc. You'd need one more integer variable to serve as the index, initialized to 0.

Then you can loop through the 1st variable and inside the loop take the value from the 2nd and 3rd variable corresponding to the index number: 1st loop take 1st item from 1st variable and item on index 0 from 2nd and 3rd variable. 2nd loop take 2nd item from 1st variable and item on index 1 from 2nd and 3rd variable, etc.

It should look similar to the flow below where I loop through 2 array variables.

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Hi @tom_riha ,

 

Thank for the reply, actually what I want is something more, maybe something too much:

 

On the request form:

          I made approver field as Lookup type and relates the default User table,

In the flow:

          I get user's primary name and their emails;

          I initialize 3 array variables;

          I start approval and append to the variables:

微信截图_20210223164043.png

         Then I need to update the approver's input

 

the problem is I don't know which approver will respond first, so I don't know which field to update first. The only way I can think of is: compare the approver's name with the value of user lookup on the request form , retrieve data form the variable and update the corresponding field if matched. But obviously it's beyond my current ability😭.

 

the workaround is to start separate approvals in parallel or in sequence and capture approvers' input separately, but that would be either time-costing or variable-costing.

 

Can you help me with this, is there a better workaround for it?

Hello @Derek4 ,

if you need to update a specific columns for specific approvers, then the arrays solution gets quite complex (and I don't know right now how I'd solve it).

I think in such situation it might be better to run the approvals in parallel branches, each role it's own parallel branch and after the approval update the respective columns in the item, e.g. one brach is 'Manager' task -> 'Assign a task and wait for response' from that manager and then update the 'Manager' columns. The same in all the other parallel branches for the other approvers. If you update the columns right after the approval, you won't even need variables.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Hi @tom_riha ,

 

I followed you advice to use parallel approvals and it gives me a "For each" while I only one approver for each approval flow, I tried to use First() as filter but I can't find dynamic content for comment in the expression...

微信截图_20210224145436.png

 

Then I tried to use "start approval" and "wait for approval" and set the approver's name as filter for a switch, but I can't use dynamic content in "Equals" field...

 

Hello @Derek4 ,

if there's only 1 user per approval action then you can leave the 'Apply to each' there. With one approver it'll have only a single response to process = 1 run of the loop.

First(...) expression expects the array with 'Responses' as the parameter, only after you select the first item from the array you can access the specific content of that response, e.g. expression to get directly display name of the approving user would look like this:

first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['responder/displayName']

Get the first(...) item from the 'Responses' output from the 'Start and wait for an approval' and take the 'Responses approval name'.

But I think it's totally fine to keep the 'Apply to each' in the flow.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,566)