cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bigfella
Regular Visitor

Trouble using an expression to avoid looping

I have a Microsoft Form that returns a FirstName LastName value for one of the responses. My flow uses the "Search for Users V2" operation on this FirstName LastName to get the UserPrincipalName. 

bigfella_0-1653064271616.png

 

I want to use this UPN as the input for the next action, Get Manager (V2). The problem is that I guess the flow assumes there could be more than one user that matches in the Search User action and automatically tries to do a "For Each" if I use the UPN as dynamic content. 

bigfella_0-1653065040716.png

 

Since I know there will only ever be a single user returned in Search for User, I want to avoid the loop. I am trying to do this with an expression. For the input to Get Manager (V2), I use outputs('Search_for_users_(V2)')?['UserPrincipalName'], but this gives me an error: The 'inputs.parameters' of workflow operation 'Get_manager_(V2)' of type 'OpenApiConnection' is not valid. Error details: The resolved string values for the following parameters are invalid, they may not be null or empty: 'id'

I've also tried it formatted outputs('Search_for_users_(V2)')?'body/value/UserPrincipalName'] and outputs('Search_for_users_(V2)')?['value/UserPrincipalName']

 

Here is the raw output to Search for Users:

bigfella_1-1653064885840.png

 

Thanks in advance!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

Search for users will always return an array of users, even if there is only one.  You can use first() around the array to get the first record, then append ?['fieldname'] to the end of that in the expressions tab to get the UPN.  Something like this

first(outputs('Search_for_users_(V2)')?['body/value'])?['UserPrincipalName']


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

View solution in original post

2 REPLIES 2
Pstork1
Dual Super User
Dual Super User

Search for users will always return an array of users, even if there is only one.  You can use first() around the array to get the first record, then append ?['fieldname'] to the end of that in the expressions tab to get the UPN.  Something like this

first(outputs('Search_for_users_(V2)')?['body/value'])?['UserPrincipalName']


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

Thank you so much, that did the trick!

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,104)