Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Checking if user already exists

(1) ShareShare
ReportReport
Posted on by 16

Hi there,

 

I've been building a flow in Power Automate and I want to check if a user already exists based on a certain value submitted through a Microsoft Forms form. 

I'm trying to do this using the Search for users (V2) function and a for each statement where it should check for users in MS365 compared to a concat it does in an earlier step. Whenever the user exists an email will be sent to the submitter of the form stating that the user already exists and they should contact the IT department.

 

Say that the first name is John and last name is Smith, it's concat to j.smith as the mail nickname. Nested in the for each I want to compare it to the user principal name (I've tested this with Nickname in the Search for users (V2) step as well) but for some reason it finds the name but doesn't check if it already exists.

 

RonVK_1-1720598230965.png

 

RonVK_0-1720598211956.png

RonVK_2-1720598244837.png

RonVK_3-1720598292504.png

 

 

Not sure what I'm doing wrong here.

 

If anyone can help me, that would be great!

 

Thank you in advance!

 

Kind regards,

 

Ron

 

  • RonVK Profile Picture
    16 on at
    Re: Checking if user already exists

    Hi Mike,

     

    Thank you for your response. Didn't quite work out as you mentioned, since it would be still within the for each loop (as far as I understood what you meant), but I've found another way around it:

     

    I've initalized a bool variable where the value is false by definition. Then whenever the for each loop is triggered it sets the value (set variable) to true whenever the statement is true (aka if user is not unique/new then the statement is set to true). After the for each loop, I've set up a condition where the value of that set variable is checked for a false statement. If the value is false it continues the flow (setup as "is not equal to true" for easy reading), if it's true it terminates the flow. 

     

    Below the setup itself:

     

     

    terminateFlow set to false by default

    RonVK_0-1720684201348.png

     

    same for each loop as before but with the terminateFlow set variable step to true if it's triggered

    RonVK_1-1720684256449.png 

    RonVK_2-1720684266415.png

     

    condition afterwards:

     

    RonVK_5-1720684342731.png

     

    RonVK_3-1720684288612.png

     

    It correctly sends me (as submitter of the form) an email stating that the user already exists (email is a concept):

     

    RonVK_6-1720684470029.png

     

    Kind regards,

     

    Ron

     

     

     

     

  • Michael E. Gernaey Profile Picture
    43,177 Super User 2025 Season 1 on at
    Re: Checking if user already exists

    Then move your below actions into the yes side. instead of outside where it will be impacted by both.

  • RonVK Profile Picture
    16 on at
    Re: Checking if user already exists

    Hi Mike,

     

    It appears to be working now. 

    Unfortunately it wont let me use a terminate flow within a for each statement:

     

    Flow save failed with code 'InvalidWorkflowRunAction' and message 'The workflow run action 'Terminate' has type 'Terminate' that could not be nested under an action of type 'foreach'.'.

     

    Do you have any idea how to bypass this?

     

    Kind regards,

     

    Ron

  • Michael E. Gernaey Profile Picture
    43,177 Super User 2025 Season 1 on at
    Re: Checking if user already exists

    Hi @RonVK 

     

    So sorry confused. So it just started working or it always work?

     

    Anyway, if you dont want it to continue if the thing is false, then add a Terminate Flow action.
    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

  • RonVK Profile Picture
    16 on at
    Re: Checking if user already exists

    Hi Mike,

     

    Thank you for your response. 

     

    Yes, the idea is that HR submits a form in which they submit information on a new co-worker. They don't provide the email address as the email address is concat from the first character of the first name, seperated with a dot (.) and completed with the last name (e.g. John Smith = j.smith@domain.com)

     

    The idea within the flow is that it should check if there's already a user within the Azure tenant with the Mail nickname j.smith and if so it should deviate from the standard flow and reply to the sender that the user is already existent within the tenant.

     

    The odd thing is, it works somehow but it still continues the flow:

     

    RonVK_0-1720620867094.png

     

    So partially it works now, it just needs to stop whenever the user already exists. 

    It will not let me use a terminate nested in a for each so that's a new thing

     

    P.s. I might've set it up incorrectly before as the flow seem to work, though it still continues.

     

    Kind regards,

     

    Ron

     

  • Michael E. Gernaey Profile Picture
    43,177 Super User 2025 Season 1 on at
    Re: Checking if user already exists

    Hi @RonVK 

     

    Let's try this.

     

    Quick validation as its not 100%. So someone is submitting a request on behalf of another person? And they don't provide the Email address of the person because they are trying to get them created?

     

    Also what does this mean exactly

    but for some reason it finds the name but doesn't check if it already exists.

    Finds the name where? In your M365 Search?

     

    If it finds it isn't that the check already to verify it exists? So not following.

     

    We need to see what your flow sees at run-time, versus what you expect, so follow these steps.

     

    1. Go to the Details Page for that Flow

    2. Click one of the Rows in the 28-day run history to open it up. Make sure its a test run that failed doing what you thought it should do

    3. Once opened, click OFF the New view, in the top right corner

     

    4. Now go down to the For Each (Apply to Each)

    5. You should either have just 1 run, or many

    6. Look at the output properties of your LookUp, and manually just look at the data and compare that to the Mail Nick value you got.

     

    If there is no match, then you know why it didn't work and you can more easily see whats up.

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >