web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Trouble making a neste...
Power Automate
Unanswered

Trouble making a nested if statement in a foreach loop

(0) ShareShare
ReportReport
Posted on by 23

I'm trying to make a foreach loop where PAD runs a subflow when the variables "Charlie", "Jane" and "Mark" don't appear on the webpage. This is how I've written it, but I'm pretty sure it's wrong as it's not working. (PAD always runs the subflow regardless). How should it be written instead? Thanks.

Screenshot (17).png

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    I am surprised it is running the subflow at all. %Browser2% is a web instance, not a string of text, so none of these would ever be satisfied.

     

    This is how I read what is displayed above:
    IF Browser2 = ‘Charlie and Jane, but not Mark’ THEN Run Subflow1. 


    I would change all the ifs to “does not contain”. It might be more than that though. Like I said, %Browser2% is a web instance which has specific properties such as URL.  You can see the properties by referencing the variable via the variable drop down inside the parameters and clicking on the drop down arrow next to the variable name. I am not sure what you intend to compare these names to:  is it a specific field? Is it in the URL?  You may need to extract text somewhere and then compare against that. Otherwise, your format works (with one caveat, remove the else if function) if you change them to ‘does not contain’, for example, if you are comparing against the URL:

     

    If %Browser2.Address% does not contain ‘Charlie’

        If %Browser2.Address% does not contain ‘Jane’

            If %Browser2.Address% does not contain ‘Mark’

                RunSubflow1

            EndIf

        EndIf

    Endif

     

     

     

     

  • VJR Profile Picture
    7,635 on at

    And to bring it in a single line and combine all the "IFs" suggested by Michael use the logical AND operator per post here.

    • NotContains(VAR, 'KEY', False)
  • ele2 Profile Picture
    23 on at

    @MichaelAnnis So would it be something like this?

    Screenshot (18).png

    I think Browser2 would need to be the property field on the webpage like you said - but I don't know how to make it into a variable (I can only get it as a UI element). 

     

    I'm trying to see if the webpage has selected one of the names in the dropdown box below: 

    Screenshot (12).png

     

    @VJR Thanks I'll take a look at that. 

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    so, I think you are on the right track. If it is a specific field, such as “manager”, then you can get the field value as a variable and then compare the field variable. So, if you have the field as a UI element, you want to “get element attribute” for the action and the attribute you want is called “Own Text”. Once you have that as a variable, you can replace all the %Browser2% variables with the %OwnText% variable. Good luck!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 425

#2
11manish Profile Picture

11manish 323 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard