cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
smather
Helper I
Helper I

Approve/ Reject - First expression

Hi there

 

I'm using the first() expression in a flow when it comes to Approve/Reject because I want to avoid Apply Each. The expression I used is this:  

 

first(body('Freelancer_Approval')?['body/responses'])

 

and this is the error message I got: 

 

Unable to process template language expressions for action 'Approved_or_Denied' at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.

 

I've successfully used first(body('Freelancer_Approval')?['responses'])?['comments'] to get the comments, but I'm unsure as to where I'm going wrong here with the response. Any help would be awesome.

 

I'm using it in a condition as in if EXPRESSION is equal to Approve; if yes, do that, if no then do that. 

1 ACCEPTED SOLUTION

Accepted Solutions

For anyone else who has this issue, I've resolved it. First by adding a compose (thanks to @MarconettiMarco  for the brain wiggle) with the following expression:

 

outputs('Freelancer_Approval')?['body/responses'][0]['approverResponse']

 

I then used the output of the compose in the condition to be equal to Approve, and everything ran as expected!

View solution in original post

11 REPLIES 11
MarconettiMarco
Resident Rockstar
Resident Rockstar

Hello @smather ,

in the "Create an approval" action you should be able to select the "Approve/Reject - First to Respond:

MarconettiMarco_0-1656339057772.png

 

In that way you can easily avoid the Apply to each control.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

 

BR,

Marco

 

 

Hi @MarconettiMarco 

 

That is the one I already have, but it still forces my flow to have an Apply Each if I use the field directly from Approve/Reject, which is why I've gone this route. 

ok, if you can, share the output of the action "Freelancer_Approval" from where you want to grab the first value.

 

BR,

Marco

Hi @MarconettiMarco 

 

Not sure what you mean, but hopefully the screenshot helps? 

 

smather_0-1656339722552.png

 

the expression in the condition is first(body('Freelancer_Approval')?['body/responses'])

Hi @smather 

you should be able to run the flow and get the output from the "Freelancer_Approval" action.

Anyhow, yon can also, after the "Freelance_Approval" action, add the "Compose" action and insert the following expression:

 

first(variables('Freelancer_Approval'))

 

then you have to add "Parse JSON" action using the Compose output value. In this way you should be able to get all the values from the first item in order to add them in the next actions.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

 

BR,

Marco

Hi @MarconettiMarco -- just an additional clarification question, sorry! In the Parse JSON, what's the required schema? 

Hi @smather ,

keep the outputs from the Compose action (so first you need to run the flow):

MarconettiMarco_0-1656403202101.png

 

then copy and paste it into the "Generate from Sample" function in the "Parse JSON" action (the Content must be the "Compose" outputs:

 

MarconettiMarco_1-1656403303543.png

and click "Done":

MarconettiMarco_2-1656403398683.png

 

So in the next Actions/Controls you should be able to get the value you want.

Please let me know.

 

BR,

Marco

 

 

Hi @MarconettiMarco 

 

Thank you! But it seems to spit out an error when I try to run it: 

 

Flow save failed with code 'InvalidVariableOperation' and message 'The inputs of workflow run action 'Compose' of type 'Compose' are not valid. The variable 'Freelancer_Approval' must be initialized before it can be used inside action 'Compose'.'.

 
I put the Compose action directly before the condition

Please share the screenshots.

 

BR,

Marco

This is what the flow looks like in its entirety 

 

smather_0-1656404675125.png

smather_1-1656404767591.png

smather_2-1656404826417.png

 

For anyone else who has this issue, I've resolved it. First by adding a compose (thanks to @MarconettiMarco  for the brain wiggle) with the following expression:

 

outputs('Freelancer_Approval')?['body/responses'][0]['approverResponse']

 

I then used the output of the compose in the condition to be equal to Approve, and everything ran as expected!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,601)