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

How to use a loop until the response value is not equal to

Hi all,

I have create below flow, which runs every hour.

PeterKl_0-1626436436158.png

In the first HTTP action I retrieve all Deployment events with a starting date in the previous hour. This might provide me several events as several deployments are started during that last hour.
This is the action:
https://graph.microsoft.com/beta/deviceManagement/autopilotEvents?$filter=microsoft.graph.DeviceMana...')}
In the second HTTP action, I retrieve some additional information regarding every event and than I use a third HTTP action to POST a message to Teams with the information I gathered.

This all runs fine. But the events can have a status of Success, Failed or inProgress. 
It's OK to post the message when the status is Success or Failed, but actually I don't want to post the message when the status is inProgress. The enrollment isn't finished and I actually want to post a message when the status changes to success or failed.
I thought about using an Until action for this. As every event is marked with an unique ID, I can run another HTTP GET action and use that ID in the filter:
https://graph.microsoft.com/beta/deviceManagement/autopilotEvents?$filter=((contains(id,'[ID]')))
But that puts my HTTP + Parse JSON action in a For each (as the ID can be present in the output of the first HTTP Action) and I'm not able to use the values from that new Parse JSON action as value for the Until action.

PeterKl_1-1626437569367.png
Does anybody know how to solve this?

Thanks in advance!

Peter

 

7 REPLIES 7
PrasadAthalye
Community Champion
Community Champion

You can declare a variable for Until loop. To start with, variable will be empty OR some default value which does not match until condition. Then after Parse JSON, you can set the variable to actual value so that loop can continue.

 

Finally you can set until condition to exit the loop. Please note that its Do Until condition and not do while. 

 

Example Until Status does not equals 'Completed' will run till the status is set to Completed.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
PeterKl
Regular Visitor

Hi @PrasadAthalye thanks for your reply. Much appreciated!

I tried to use a Variable, but maybe I did something wrong with that, as it didn't work as expected. My flow looks like this with a variable:

PeterKl_1-1626602499228.png


The thing with above flow is, when multiple events are retrieved, the Until is finished for all events as soon as one of the events hits a Success/ Failure status. I expected the event with inProgress status to continue the Until loop until that event also hits Success or Failure. 

If only one event is received, the until action works fine. So the thing is, how to split this up so every event with the until action is handled separate?

Thanks,

Peter

Ok I think you can achieve this with simple approach. Because you essentially do not want to notify for In Progress events. It can be done without until because you are on a scheduled trigger. 

  • Get All your events with the filter not equal to In progress.
  • Send notifications for all of them.
  • Next time when your flow runs on a schedule, it will continue to filter new Success\Failure status events and you can notify. This can continue until all In progress events are done.

Do you think this approach will work?

 

 

 

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
PeterKl
Regular Visitor

Thanks for your response.

What kind of filter should I use for this. I now filter the events from the past hours (already in the GET HTTP Action url), because when I don't do that I get all events from the last 30 days. By using that filter, at least I'm sure I only get new events.

Thanks,

 

Peter

I understand. Some filter additional to existing one that filters output by status not equals to in progress.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

@PeterKl , I'm just looking through this, and one of the key drawbacks to something you mentioned was that  wanted to do something but couldn't due to the for each part.

 

Well, you can select array items using "[1]" in functions.

 

I'm going to take a more in-depth look at it to see if there's an easy solution, here, but if there is I have a sneaking suspicion that picking the right array item might be that solution. 🙂

 

----

Further editing to ask perhaps a silly question followed by a suggestion based on that question answer being 'yes' 😉:

  1. Could you utilise a separate SharePoint list to just process the data?
  2. Then have a separate flow post the Teams messages based on the status of a given [id]'s in the list?

 

I'm not discounting that there's a way to do this with the JSON arrays in the flow (and I'm still looking at that), but this would definitely simplify the logic for you and potentially show you the answer with the JSON data.

 

It would also give you decent archival data on them.

 

----

 

OK, it can definitely be done with arrays, but it got too painful for me to carry on figuring out the logic for you.

 

Essentially, though, I would start by splitting your data into two sets that you'll work with in separate branches:

  1. Branch One; takes all the initial results that are completed or Failed and processes them immediately into Teams messages.
  2. Branch Two; only takes all the initial results that are "In-Progress" and creates a secondary array to work on.

Now you only have one set of data that you need to concentrate on, Branch Two. 🙂

 

(you can alternatively build a master array and add both branches to it to spam the teams thread all at once, too)

 

You can then work on whittling down the second set of data using a third array variable (that gets wiped on each iterative turn of the UNTIL action), and once that array is emptied of "In-Progress" statuses you can set a boolean 'isGood' variable to true, and the UNTIL can stop.

 

I think one of my previous posts handles whittling an array, however that's a whole 'nother thing, and I genuinely don't have the spare brain matter to push at it right now. But I'm not here to get points, just hope that what little I do say can help point you in the right direction.

 

Sorry I can't be more specific, but I started to build it out, and then realised I'd have to start faking your data input, and honestly, it was too much work. 😅 

 

I would definitely advise, though, creating a SharePoint list to just iterate through what's new/in-progress/done, and work from there, though.

 

Hope you get it sorted, however you do it! 🙂

PeterKl
Regular Visitor

First of all, thanks for your long reply!

 

It's already hard for me to get test data, as it involves a device enrollment and the inProgress status isn't there forever 🙂

I'm not sure what you mean my this. I'm only working with flows for a couple of months
"You can then work on whittling down the second set of data using a third array variable (that gets wiped on each iterative turn of the UNTIL action), and once that array is emptied of "In-Progress" statuses you can set a boolean 'isGood' variable to true, and the UNTIL can stop."

As I don't prefer a solution with a SharePoint, I can create one. But I guess instead of using a filter (expression) in the first HTTP GET action to only retrieve the events from the latest hour, I need to get all events? Which means I get hundreds of events in the list.
And than I need to make sure that the flow which retrieves the events compares the retrieved values with the ones in the SP list. When the SP List event has a value of inProgress and the retrieved value is success/ failed, need to change the status on the SP List.
A second flow would check the SP List for changed items and process these, but only when the status is success/ failure.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (924)