cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
brego
Frequent Visitor

Trying to use a field from previous 'Apply to each' step to log Flow history

Hi, sorry this is so long, I am stuck. I created a multi-stage approval in Power Automate to work through a business process with multiple approvers. The Flow has five 'Start and wait for approval' steps. Each approval step provides approvers the option to log their comments about the step. I have a requirement to log these comments into a running log during each Flow run and I wish to write the comments as history values into a multi-line field in SharePoint along with a time calculation to show how long an approver needed to make their decision. For context, I am attempting to replicate the approach shared by @RezaDorrani in his YouTube video called "Build long running approval flows with Power Automate". 

 

Each of the 5 approvals in the Flow has an 'Update SharePoint Item' step that utilizes the 'responder' for that approval level. During the build, when I add the responder/DisplayName from the apply to each to the update field that will store the history, Flow automatically wraps the approval status item into an 'Apply to each' loop. I am having trouble getting the comment history value to write from any approval beyond the first approval in this Flow because the Update SharePoint Item step in the second approval and beyond cannot access the history value from the previous approval; that history field is not available in the dynamic content since it is part of an apply to each. I attempt to get at the first item in the apply to each array but fail to capture the desired string.

 

For example, on the technician approval step, I am trying to access the history item from the previous approval step and its apply to each array to write that value to this step's WF_History field by using:  "body('Water_doc_approval_Apply_to_each')[0]['WF_History']". This errors out and cannot access that data.

 

I think I am just not getting how to get at the data that is obviously there in the JSON and it, frankly, is driving me bonkers. Does anyone have an idea how I can access the history field from the previous step's JSON and write it to the current step, and so on? The intent is to take the comments from each approval step and log them into a history field in the SharePoint list.  

 

If it helps at all, I get the following error: 

InvalidTemplate. Unable to process template language expressions in action 'Technician_Processing_Approval_Apply_to_each' inputs at line '1' and column '38876': 'The template language expression 'body(Technician_Processing_Approval_Apply_to_each)[0]['WF_History']' cannot be evaluated because property '0' cannot be selected. Please see https://aka.ms/logicexpressions  for usage details.'.

 

Thank you and Happy New Years!

1 ACCEPTED SOLUTION

Accepted Solutions
brego
Frequent Visitor

Aha, yes it is possible! Just add a Get File Properties just below each approval so that the item's history is available in dynamic content when you update the SharePoint list for the item's history.  👍

View solution in original post

5 REPLIES 5
annajhaveri
Super User
Super User

@brego , can you share the screenshot of your flow and point in the screenshot where you facing the issue, to better understand it.

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
brego
Frequent Visitor

Thank you @annajhaveri. Here is a screen shot:

 

Second Approval: FocusSecond Approval: Focus

Add a Get File Properties stepAdd a Get File Properties step

@brego , it looks like issue with the body('Water_doc_approval_Apply_to_each')[0]['WF_History']), there is no such property of the approval responses from approval action, what do you need approver comments?

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
brego
Frequent Visitor

@annajhaveri thank you for taking a look. I think I understand what you may be pointing out; the WF_History from the Water_doc_approval_Apply_to_each is not available to the Engineer approval step. Do you think it possible to access the WF_History value from the previous approval's Apply to Each? 

brego
Frequent Visitor

Aha, yes it is possible! Just add a Get File Properties just below each approval so that the item's history is available in dynamic content when you update the SharePoint list for the item's history.  👍

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

New Process Advisor Capabilities carousel.png

Read the blog for the latest news

Read the latest about new experiences and capabilities in the Power Automate product blog.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

AI Builder AMA June 7th carousel (up on May 25th, take down June 8th) (1).png

'Ask Microsoft Anything' about AI Builder!

The AI Builder team invite you to ask questions and provide helpful answers at our next AMA.

Users online (1,800)