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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Conditional Loop with ...
Power Automate
Unanswered

Conditional Loop with If statement

(0) ShareShare
ReportReport
Posted on by 6

Hi,

I have created a enable/disable account with loops to click around on website to make sure website doesn't timeout every 60mins


I have a Task to start at 7am.
Actions to enable account,
Loop until if =greaterthan 7pm, exit loop (To keep the website active, otherwise timedsout) (It clicks around every 30mins the website etc)
Action to disable account at 7pm.
Loop until if =greaterthan 6:55am - This is the part it's not catching. (to click around website overnight to keep active).
I've tried changing it to =lessthan 6:55am, but i'm stumped!
So when starting task the next morning fails because session timedout overnight

In both loops I have currentdatetime also tried with date to text, thinking maybe that's why I wasn't catching.
I know i'm close which is why it's so frustrating!
Thank you in advance!!

I have the same question (0)
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Can you please share some screenshots of the date formatting and the IF condition that does not work for you?

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    It would help if you share your flow screenshots, especially at the 655am capture and part. 

    my 1st guess is that your time is not just the time. For example, if you are using CurrentDateTime, it may always be after 7pm, because the date is included.  The original date is day 1, 655am, not day 2, 655am. 

    with that being said, let’s try this:

     

    Enable account

    Loop while 1=1
        set %Account% to “Enabled”

        get currentdatetime

        convert datetime to text hh as %time_hour%

        Switch %time_hour%

            Case >= 19

                If %Account% = “Enabled”

                    Disable account

                    Set %Account% to “Disabled%

                End (if)

            Case >= 7

                If %Account% = “Disabled”

                    Enable Account

                End (if)

        End (Switch)

        Wait 30 minutes

        Click on website

    End (Loop)

     

    this will loop infinitely and flip it the first time it comes back after 1900 and 700. 

    can make it more precise if it matters but you get the idea. 

    good luck!

  • Will_H Profile Picture
    6 on at

    Hi guys,

    Thank you for you responses.
    Step 1-13 is the enable account steps - open browser, search for user, find "Enable" button click etc.
    Step 14-25 is the loop to click around website to keep website session active till 7pm then exit loop
    Step 26-37 search for user, find "Disable" button click etc.
    Step 38-49 is the loop that clicks around website to keep session active till 7am  - This is the loop that doesn't catch. As a result because the loop doesn't catch and exits loop, the websession then expires when the script runs again at 6am.

    Screenshot 2023-09-15 at 9.24.57 AM.png

    Screenshot 2023-09-15 at 9.26.21 AM.png

    I'm fairly new to Power Automate, so I could have fumbled my way and written this NOT the best practise way.
    I did see one where it looped 1-X times with pauses which equalled to 11h:55m for loop but problem was if I had to extend disable to say 9pm then means account wouldn't be enabled till 9am next morning not 7am.

    Thank you so much!

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Well, the problem here is clearly related to the formats you use in your Convert date time to text actions and the conditions. You're converting it using "HH:mm:ss" as the format, but you're using "HH:mm tt" as the format in the conditions - i.e. not including the seconds, but including the AM/PM definition, which makes no sense.

     

    Try using "07:00:00" and "19:00:00" instead of "7:00 AM" and "7:00 PM" in your If conditions.

     

    Also, make sure you do include the leading zero in "07:00:00". This is because you're essentially comparing strings (due to the : separator) and as such the strings are compared alphabetically. So, "1:00:00" will be greater than "07:00:00", because 1 is greater than 0.

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

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard