How to – Use Do until and Delay in Power Automate


Let us take a simple example to understand the usage of the Do unit with Delay control in Power Automate.

“When a Case Record’s Priority is updated to High until the case is resolved we want to perform certain action e.g. send a notification email or call an action etc. every 2 minutes or so.”

This is how the final flow looks like –

First is the trigger, when the case record is modified, i.e. priority code field with value as 1.

Next, initialize a Boolean type variable as false, this will be used within the Do until loop condition.

  • Next, add the Do until control with the condition – ConditionMet i.e. the variable is equal to true.
  • Followed by Delay action, here we have specified a 2-minute delay.
  • Next, we are retrieving the same record to check the condition, this is required to get the updated value within the loop.
  • Condition is – is the case resolved? i.e. Status is equal to 1.
  • If Yes then we are setting the variable as true to come out of the do until loop.
  • If No then we perform any action, like send an email notification, reminder or call any action, etc.

The Current Iteration Index of Do unit holds the value of the current index starting from 0. Here we are updating the case title with the index just for testing.

To see it in action, let us Test the flow.

Updating the priority of the case to high triggers the flow.

After a delay of 6 minutes, we can see the Case Title updated with the current index i.e. 2 as it has iterated 3 times starting from 0.

Let us now resolve the case.

We can see our flow successfully completed after the 4th iteration after the case is resolved.

Also refer –

https://techwizard.cloud/2018/05/20/microsoft-flow-mystery-of-do-until-loop/

https://www.futurelearn.com/info/courses/cloudswyft-msft-dynamics-365-power-platform-auto/0/steps/208142

Hope it helps.

Advertisements

Solved – Flow run timed out. Please try again in Power Automate (Microsoft Flow)


While testing one of the flows which was having “Do until” action in it, we ran across the below error.

Error – Flow run timed out. Please try again.

However, while navigating to the run history we can still see the flow running, and has run for over 30 minutes. That’s the default behavior.

Refer to this – https://powerusers.microsoft.com/t5/General-Power-Automate/Flow-run-timed-out/m-p/713628#M58900

Hope it helps..

Advertisements

5000 records limit of Fetch XML Query – List records action of Common Data Service (current environment) connector in Power Automate


Recently in one of our requirements, while trying to fetch contact records using Fetch XML Query

https://docs.microsoft.com/en-us/connectors/commondataserviceforapps/#list-records

we realized that we can only retrieve / fetch 5000 records.

Enabling pagination will also not help here (the Next link also come as null).

The alternate solution is to convert the Fetch XML query to OData and use the same inside List records action

https://fetchxmlbuilder.com/features/#render-flow

Get more details here

https://evolved365.com/2020/10/06/working-with-large-cds-datasets-in-power-automate-flows-and-logic-apps/

Hope it helps..

Advertisements

A simple implementation using Azure Functions, Microsoft Flow, Microsoft PowerApps, Dynamics CRM and SendGrid


Let us  implement a simple scenario where we create a lead record in CRM which then talks with Flow (and Power App).

The Flow calls an Azure Function (Custom API) that sends mail to the lead’s email address using SendGrid

1) Let us create an Azure Function that uses SendGrid to send email to the lead’s email address.

Login to Azure Portal and create a new Function App.

https://portal.azure.com

Let us create a Function using Generic Web Hook CSharp template

To keep it simple let us only enable GET method. Go to Integrate tab and in Allowed HTTP Methods Select Selected Methods and check GET.

Also set mode as Standard and Authorization Level as anonymous, which means we do not need a API Key to be passed as query parameter to talk with the function.

Now let us add a new Output

Select SendGrid as the template

Click on Save.

Here we would need to define SendGridApiKey.

Go to SendGrid portal and create a free account over there

https://sendgrid.com

Create and API Key and copy it’s value.

Now go to Application Settings of the Function App and set this key value with SendGridApiKey as the key name.

Now let us go back to our code and update it to work with lead object and Mail class which would be used for sending email using SendGrid API.

Here first we are referring the SendGrid assembly, then getting fullname and email from query string and then creating Mail object.

Save and check the log if the compilation succeeded or not.

Testing our Function.

We can see the mail in the mail box.

This completes our first part.

2) Now let us create the Swagger definition for it which we will use in Power Apps and Microsoft Flows for using this Azure Function as Custom API.

Select our function and click on API definition.

Click on Function.

Update the generated API Definition Template with query parameter details and also test it.

As it is running successfully, click on Export to Power Apps + Flow

This opens up the new section that details the steps we need to follow for using our Azure Function with Power Apps and Microsoft Flow.

There click on Download button.

Click on Go to PowerApps

It opens up the PowerApps portal (asks for log in) and opens the New Connection page.

https://web.powerapps.com

Upload the JSON Definition file for our Azure Function, provide name and description and click on Next.

Click on Create.

Let us quickly test our new connection.

Click on New App in our PowerApps web portal.

Select PowerApps Studio for Web. Let us create a Blank App Phone.

Add a new Data Source and select our Azure Function there.

To get the API Key go to our function and expand API Definition Key.

It works properly.

3) Now let us move to our last step, wherein we use it inside Microsoft Flow and integrate it with Dynamics CRM.

The good thing is to configure the same for Microsoft Flow, we do not have to do any extra step as both Microsoft Flow and PowerApps share the same connection infra.

Go to Microsoft Flow portal

https://flow.microsoft.com/

We can find our Custom API already added there.

Let us create a new flow. Start with Dynamics 365.

When a record is created. Select Organization Name and Leads as the entity and click on Add an Action.

Search for our Custom API.

Select LastName and Email as Dynamic Content from the lead record created.

Click on Create Flow to create the flow.

Unfortunately, we get the below error

Let us go back to our Swagger Definition and update it.

We have updated it as following

Let us quickly test it, import it in Power Apps as new connection and come back to our Flow.

Edit the connection there and specify the API Key as we had done earlier inside Power Apps and update it.

Open Flow and quickly add the required steps and click on Create Flow.

We have successfully created our flow. Now let us test it.

Let us create a new lead record

Our flow runs and sends the mail

That’s it we are done with our simple implementation. The main purpose of this post was to show the integration possibilities which could help us design and implement real world complex scenarios.

Hope it helps..

“Create Dynamics Leads based on Tweets” using Microsoft Flow in CRM 2016


Microsoft Flow is a workflow management tool, using which we can create automated workflows between various services and apps.

With Dynamics CRM Online common scenarios could be

  • Create Dynamics CRM Leads from an Excel table.
  • When an opportunity is created post to Yammer.
  • Copy new Dynamic CRM Account to Common Data Model etc.

https://flow.microsoft.com/en-us/

https://flow.microsoft.com/en-us/services/shared_dynamicscrmonline/dynamics-crm-online/

  • Below are some of the templates available for CRM Online

  • Let us take a Template that creates Leads based on Tweets

  • Connect to both the services

  • Configure it, for e.g. search for #msdyn365, get the Tweeter User Name and create the lead record. Map topic in lead with tweet text.

  • Check the status of the flow.

  • Leads created in CRM

Hope it helps..

%d bloggers like this: