Tag Archives: Power Automate

Convert an Array to string in Power Automate/ Microsoft Flow

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Power Automate Compose function is indeed quite powerful and if you have designed a complex flow, chances are you have used it in one of the flow steps.

However there are so many hidden gems in the Compose action itself that sometimes it is difficult to keep track of all the features. And one such feature is the ability to convert a array to string.

For example I am receiving an array of countries in the below format

[
    "India",
    "US",
    "UK",
    "Canada"
]

And I need to convert it to a string separated by comma. Well very simple right? If you are from a programming background, you will think surely there would be something like string.join right?

Well, it’s not exactly string.join but infact there is a JOIN compose operation which does that. So let’s see that in action.

image

image

And let’s see the output.

image

And voila! You have the output separated by comma.

Wonderful isn’t it?

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Export Power Automate/ Microsoft flow run history

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Way back when Power Automate was introduced, there was no way to export Flow run history. As surprising it may sound today, there was no way to export the flow run history when flow as introduced.

You may be thinking – “You must be joking man!”. Actually am not. Anyways bygones are bygones.

The good part is the current version of Power Automate have the capability to export Flow run history. To export flow run history, open up a flow and then click on Run History

image

It will take you to the Run history for the flow.

image

Now you have the option to export the Flow run as .CSV file.

image

That will download all the flow runs. The run history download file is a detailed report with all the data related to the run including the input and output for each flow step.

image

You also have the capability to export data from specific views and export specific data. For example you can export the data only for failed runs to understand why the flow runs failed.

image

A simple but very handy information to know.

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Copy Notes with Attachments when a lead is qualified to Opportunity in Dynamics 365

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Starting from templates is a great way to start learning flows” – This is one of the recommendations I learned during my preparation for Microsoft Certification.

And I realized it today when I had to solve one requirement for my customer. So the requirement was to copy notes from a lead to the opportunity record when the lead is qualified. Quite a simple stuff. If you are a Dynamics 365 Pro, you may be thinking – Isn’t it something which Dynamics 365 does OOB.

Yes it does. But does it really copies of the Notes to Opportunities? Let’s explore this a bit more.

So I have this lead and I have added a Note – “Lead Note 1”. Also observe I have an attachment in the note.

image

Now I qualify this lead to Opportunity. Once the lead is qualified to Opportunity, I could see the Lead Note showing up in Opportunity timeline as well.

image

Well it’s done right? Not quite. And trust me, superficially it shows up in the Opportunity entity timeline and many believe that it is being copied over to Opportunity. But in-fact, it is still tied to Lead. To verify this, I open up Advanced Find and search for this note record. I could see only one note record and that too being attached to the lead record.

image

So we understood, it really didn’t copy over the Note. So now how do I accomplish this? Just when I was about to write my flow, I came across this by chance in the existing templates.

image

Such a useful template by CRM Innovation LLC. It’s just an addition to all the great work they are already doing for Dynamics Community.

All you need to do is open up this template and then set up the connection with your CDS/ Dynamics 365 environment accordingly.

image

And now when I qualify the lead to opportunity, I can see the Notes record getting copied over along with attachment (if any) to the Opportunity record.

To verify in advanced find, I have now two notes record – one for lead and one for opportunity.

image

A very good learning for me. And hope you found it interesting too!

Debajit Dutta

(Microsoft MVP)

Parse XML in Power Automate/ Microsoft Flow

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

The simplest of things are sometimes the sweetest. And here is this one requirement to parse an XML using Power Automate/ Microsoft Flow.

With SOAP giving away to REST based API’s, XML parsing is gradually going out of fashion. But still there are some scenarios where you need to go ahead and do XML parsing. So let’s see how can you do that in Microsoft Flow.

Let’s say you have the following input XML.

<response>
   <status>failure</status>
   <reason>duplicate</reason>
   <recordid>0123456789</recordid>
   <url>https://www.google.com</url>
</response>

What I want is to take a decision based on the status value. So let’s see how I can do this.

Here is the Input Xml.

image

The next step we need is to parse the XML. For that we will use the Compose Action.

In the inputs section, we use this formula – xpath(xml(outputs(‘Input_Xml’)), ‘string(/response/status)’)

image

As you can see in the above step, we are using the xpath formula and then try to parse the status field using the path  – /response/status and then typecasting it to string using the string() construct. Please note that the typecast is necessary. Otherwise the returned results will be an array.

Next we use the Initialize Variable action to set the value from the output of the previous Compose step.

image

And below is the test run.

image

As you can see, we are able to successfully parse the Status field from XML. You can now use the Status field for further processing.

Off-course, the complexity of the XML may vary. But the logic remains same.

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Using EntityCollection as Output parameter of Dynamics 365 Action while calling Action from Microsoft Power Automate (Flow)

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

In that blog I explicitly mentioned on the problem of using EntityCollection as output parameter and suggested a possible solution to that. After multiple request from my blog readers, I am writing this blog on how you can use EntityCollection as output parameter of your action that you are invoking through flow. Well may not be exact EntityCollection output parameter but you can accomplish the same purpose.

So first – What’s all the problem with EntityCollection as output parameter? This is because when you set output parameter of type EntityCollection, the action would need an output of type Array. If you use EntityCollection as output parameter, you would get an error similar to the one below.

The API operation ‘PerformUnboundAction’ requires the property ‘body’ to be of type ‘Array’ but is of type ‘Object’.

Well Entity Collection contains the list of entity but after all in CRM it is not an array whereas in Flow it is expected as array.

So what is the other option. Well there can be many different ways but the easiest is to get the JSON representation of your entity collection and then parse in back in the flow. So without wasting more time, let’s jump inside the flow.

Microsoft Power Automate - YouTube

First of all, I create an action in Dynamics 365 and use and Output parameter named – EntCollString of type string. Observe I am not using the parameter of type EntityCollection but string.

image

For this demo, I have written a plugin on Post-operation of this plugin. Below is plugin sample code.

var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
         var sf = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

  var s = sf.CreateOrganizationService(context.UserId);

        QueryExpression exp = new QueryExpression
         {
            EntityName = "account",
            TopCount = 10,
            ColumnSet = new ColumnSet("name")
         };

        var results = s.RetrieveMultiple(exp);

        var entResults = new List<Tuple<string, Guid>>();
         results.Entities.ToList().ForEach(x =>
         {
            entResults.Add(new Tuple<string, Guid>(x.GetAttributeValue<string>("name"), x.Id));
         });

        var memoryStream = new MemoryStream();
         DataContractJsonSerializer dataContractSerializer = new DataContractJsonSerializer(typeof(List<Tuple<string,Guid>>));
         dataContractSerializer.WriteObject(memoryStream, results.Entities.ToList());
         memoryStream.Position = 0;

        var sr = new StreamReader(memoryStream);
     context.OutputParameters["EntCollString"] = sr.ReadToEnd();

If you observe the code, I am taking a list of 10 account, getting their name and id and then passing it back as the output parameter of the action by serializing them into JSON.

Nothing much in that. Offcourse we have less attributes here but you can apply the same with more attributes.

Now comes the important part here. That is the follow. I invoke the action, I get the data in output collection and then parse the JSON.

image

To parse the JSON, I am using the ParseJSON data operation. For the schema you would need a sample data which you can easily get by doing a test run of your code, getting the JSON result and then generating the schema using “Generate from sample” button.

image

And then iterating through each item of the JSON array. In the code I have used C# Tuples. And hence the property names came as m_item1 and m_Item2. However if you use a strongly typed class, you shall get the names with the exact property names you have specified in the class.

image

And that’s all. Now you have same stuff that would you have done using entitycollection as output parameter. Yes a little bit of workaround but certainly worth it.

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Common Data Service (Current environment) connector not showing up while creating a PowerAutomate flow? Check this out.

Couple of months back I wrote a blog post on Common data service (Current environment) not showing up while creating a PowerAutomate flow and the reason was that only for flows created through the solution have the connector available.

Here is the link to the post – https://debajmecrm.com/2019/11/24/quick-tip-common-data-service-current-environment-connector-not-showing-up-while-creating-microsoft-flows-power-automate/comment-page-1/#comment-17413

However post that I got multiple question on other scenarios related to the same topic and I thought of devoting a separate article for that. So here goes the questions.

Q1. I have a PowerAutomate flow originally created outside a solution. I have now included it in a solution. Will my flow be able to use the Common data service (Current environment) connector?

Answer: No it won’t be able to. The reason is, the connector is only available for flows which were originally created from within a solution. Since here it was created outside and then later included as part of the solution, it won’t be able to use the connector.

Q2. I have PowerAutomate flow created in Solution A in which I didn’t use the CDS current environment connector. I now have solution B in which I have added the flow and now I plan to use the connector. Is this possible?

Answer: Yes, the connector shall now be available because the flow itself was originally created from inside Solution A and not outside of solutions.

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)