cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
johnc222
Helper III
Helper III

Populate word template / apply to each?

Hello all - experiencing this issue below when trying to parse JSON data then populating a word template. 

 

Flow tries to do apply for all loop, which causes basically 6 different sets of information. Im sure this is a simple logic fix but i cant seem to figure out how to get this to fill *one* form and email once? Any suggestions?

 

at this point it generates 6 different emails and 6 different .docx attachments. 

 

johnc222_0-1617971494616.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @johnc222 

 

Take a look at the first() expression. It will return the first object in your array and avoid the need for an apply to each. Same as the earlier method but easier. You can call your 6 key values using the first() expression.

 

Here is a blog post explaining same: https://365basics.com/microsoft-flow-2-methods-to-not-use-apply-to-each-action-when-only-a-single-fi...

 

I need to write my own post 😉

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

View solution in original post

5 REPLIES 5
DamoBird365
Microsoft
Microsoft

Hi @johnc222 

 

Power Automate will stick an array into an apply to each if it suspectes there will be multiple results.  If you are confident there is only one, you can call the first by sticking ?[0]? in your expression, elements start at 0.

 

If you share more info on your data source and the history of the output I can give you more specific advice.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

I guess I am kind of confused on what you are suggesting

 

So right now it pulls in 6 different values from my JSON parse. I want it to send an email listing all values at once, even if they are null - right now the For Each will run 6 different times once for each value.

 

Removed the populate word doc in replace of just email - but still same problem. 

 

johnc222_0-1618258257033.png

 

Hi @johnc222 

 

Take a look at the first() expression. It will return the first object in your array and avoid the need for an apply to each. Same as the earlier method but easier. You can call your 6 key values using the first() expression.

 

Here is a blog post explaining same: https://365basics.com/microsoft-flow-2-methods-to-not-use-apply-to-each-action-when-only-a-single-fi...

 

I need to write my own post 😉

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

Hello Damo,

 

I tried to follow the blog post you attached but it appears the functions they mention are no longer the same for edit in advanced mode.

 

When i try to manually type first() function and one of my parsed items it will apply another "Apply to each"

 

What is the value i need to enter on the right? Sorry just a tad confused here

 

johnc222_0-1618315373959.png

 

 

 

johnc222_1-1618315567747.png

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,435)