Showing posts with label Power Automate. Show all posts
Showing posts with label Power Automate. Show all posts

Sunday, 30 August 2020

List Records Output not showing in Power Automate/Microsoft Flow

Hi Everyone,

Today I have configured a CDS List Records step in flow to retrieve some records and I have to parse them and do some operation. We all know that for Parse JSON step, we have to give schema. In these type of cases, usually we run the flow first till List Records step and copy the output from that step and give copied output to generate schema in Parse JSON step.

When I was doing the same, unfortunately the list records steps is not showing output and not giving any option to download the result as well. I was kind of stuck with that and by doing quick search came to know that we can Compose Step  give the output the List Records step to Compose step so that we can see the result and use it for generating schema.


Hope this helps

--
Happy 365'ing
Gopinath

Get a single/first record from CDS/Dynamics 365 List Records action step in Power Automate/Microsoft Flow


Hi Everyone,

Today I was working on Microsoft Flow and I have List Records step configured in the flow. As per the requirement, I know that the result of the List Records step would be one record or empty. We all know that to get the data from List Record, normally go with Apply to each step as I already know that the output count of records would not be more than 1 taken below approach.

List Records Step  -->  Take the required values using First function.

first(body('List_records')?['value'])?['accountid']

This returns empty string if the count is 0 else the value.


Hope this helps

--
Happy 365'ing
Gopinath

Sunday, 19 July 2020

Call Power Automate or Microsoft Flow from JavaScript - Dynamics 365 CE

Hi Everyone,

We all know how Power Automate or Microsoft Flows are changing the way we design the things in Dynamics 365 CE. Recently, we got a requirement to call Microsoft Flow from a button click on Dynamics 365. Here is the way we did using JavaScript.

Let's create a flow as below.

1) Take the trigger as HTTP Request received

2) Generate Schema accordingly to your input, I just have AccountID as an Input so taken JSON as below to generate schema and declare the method as POST.
{"AccountId": "abc"}

3) I just added one step of Variable as once the flows is triggered from the JavaScript, we can add the steps as per our requirement.

4) Save the flow and get the URL from HTTP Trigger (first step)

5) Here is the JavaScript code for calling flow.
function callFlowFromJavaScript() {
    var flowUrl = "FLOW URL";
    var input = JSON.stringify({
        "AccountId": "475b158c-541c-e511-80d3-3863bb347ba8"
    });
    var req = new XMLHttpRequest();
    req.open("POST", flowUrl, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send(input);

}
To Configure Flow URL in a best way, you can read this Post.

Hope this helps.

--
Happy 365'ing
Gopinath.

Thursday, 16 July 2020

Invalid type. Expected String but got Null or Invalid type, Expecting Object but got Null - Microsoft Flow/Power Automate

Hi Everyone,

Today I was working on flows and all of a sudden flow started failing with the below error at Parse JSON step.

"Invalid type. Expected String but got Null"

However, was able to understand the issue after checking the input that was passed to Parse JSON step. One of the property value is coming as Null.

The fix is easy, we just need modify the Schema of Parse JSON.

instead of  "type": "string" make it as "type": ["string", "null"] to handle null values.

Hope this helps.

--
Happy 365'ing
Gopinath.

Sunday, 12 July 2020

Required properties are missing from object while parsing JSON in Power Automate or Microsoft Flow

Hi Everyone,

Today I am working on a flow and received below error at ParseJSON Step.

"Required properties are missing from object : property names"


This error is coming as we have specified some of the properties as required in the Schema and as they are not given as an input to Parse JSON, the step is failing while validating the data with schema.

To fix this, we have to edit the schema and remove the properties that were mentioned as Required in the schema. 



If you are 100% clear that you might need the values to pass on, I would be prefer to check the data after parsing it and have your own response step to handle it.

Hope this helps.

--
Happy 365'ing
Gopinath

Get the records from Power Automate (List Records) and display them on the Gallery - Power Platform - Dynamics 365, CDS, Power Automate and Canvas App

Hi Everyone,

In this post, let's try to understand the steps that are needed to get the data from Power Automate using Common Data Service List Records Action and show the same on the Canvas App Gallery.

As a first step, let's build Power Automate to get records from Dynamics 365. 

Take a trigger as a PowerApps as we would calling this flow from Canvas App.

Add Common Data Service Current Environment Connector and List Records step by defining the entity and fields you would like to get.

Run the flow to get the results so that you can generate JSON Schema with that. 
Expand List Records step and click on Download link. It will open the JSON results in the browser window.


Select one record from the result and copy, we will use it to generate schema.

Add Parse JSON step in the flow as next step and take values from List Records steps as an Input to the step.

Click on "Generate from Sample" button on Parse JSON step and put the JSON data that was copied by adding "[" as a starting character and "]" as an ending character so that the result would be converted to an Array.

Once the Schema is generated, make sure you remove the column names in the Required property otherwise your flow would fail with error "Required Properties are missing from object" if some values comes as blank in the result. 


Run the flow once to check the output from Parse JSON step.
The flow ran successfully and you would be able to see the output from Parse JSON step.

Edit the flow and add Response Step, set Body of Response to Body of Parse JSON step.


Click on Show advanced options link and copy the schema from Parse JSON step and put it here.
Save the flow.

Let's create a new Canvas App and add go to Action, Power Automate which will show the list of the flows in your environment.

Select the flow that you would want to use and after adding the flow to Canvas App, provide Parameters if you have any otherwise close the command with parenthesis.

As we need to bind the data to Gallery, we need a Collection object. Let's push the result from flow to a collection. To test the things easily, I have added a button and OnSelect of the button given below statements. This will get the result from flow and assign it to the collection.

ClearCollect(DataFromFlowCollection, GetAccountsFromD365CE.Run());

Let's test it once before we add Gallery to the app. Play the app and click on the button. After the execution, go back to edit mode --> View --> Collections, you can preview the data.

We are able to get the data from flow to CanvasApp, let's add Gallery and bind the collection as a Data Source to it.

You can click on Edit link beside Fields and select which fields you would like to display.

Let's play the App and click on Get Data button to show the data on Gallery.

Hope this helps.

--
Happy App Development
Gopinath

Monday, 22 June 2020

Make use of Terminate Action in Flow/Power Automate

Hi Everyone,

Today I was talking to one my friends and he asked a question on how to stop the flow execution at a specified some point. I didn't get his question for the first time when I heard. 

Here is the good explanation of it.

Let's say we have a flow that has more than 30 steps and we all know how often requirement changes. I am changing the existing flow and want to execute the flow till 10 steps to understand whether I am going in a right direction or not. In C# or any coding language, we just use return statement to skip the further execution and how can we achieve the same in Flow?

I was wondering if we have any such option and finally Terminate action is the savior here. We can use Terminate Action where we would like to return and run the flow, the execution will be stopped once it reaches to Terminate action. 

Hope this helps.

--
Happy 365'ing
Gopinath

Friday, 19 June 2020

Best Practice - Adding Comments in Power Automate/Flows

Hi Everyone,

Today I was going through the settings of one of the Actions in Flow and have seen "Add a comment".  

We all know the best practice of adding comments in all programming languages and it is the same in Flows as well. As a best practice, let's put few words on what exactly we are doing in the comments. 

Hope this helps.

--
Happy 365'ing
Gopinath

Power Platform Analytics - Common Data Service, Power Automate and Power Apps

Hi Everyone,

Today I was going through Power Platform Admin Center and checked Analytics from the navigation. I remembered the days where we used to install Organization insights managed solution and check active/inactive users, storage usage, plugins success rate etc.

Now, we don't need any solution to install and there are lot more useful information to understand the system health from these analytics.

There are three analytics available, check Microsoft Docs (links below) to understand more on the roles that are needed to view the analytics and the information that would be provided.

1) Common Data Service  - Microsoft Docs Link

2) Power Automate  - Microsoft Docs Link

3) Power Apps  - Microsoft Docs Link

Hope this helps.

--
Happy 365'ing
Gopinath

Thursday, 18 June 2020

Get the Count of records in Flow or Power Automate - Dynamics 365 CE

Hi Everyone,

Today I got a requirement to check the record count and do some operation if the count is greater than 1. We are very much used to these kind of checks in C# and just think if we need to the same in Flow.

Here is the way to do. We just need to know one expression for doing it. 

I have a following Action of List Records from CDS connector and renamed it to ListOfAccounts.

Declared an Integer variable and below the expression used for setting the value.

length(body('ListOfAccounts')?['value'])

Once we run the flow, the variable will have the count of accounts that are retrieved by List Records action. We can use same expression in conditions.

Hope this helps.

--
Happy 365'ing
Gopinath

Thursday, 11 June 2020

Create Record in Dynamics 365 CE Using Power Apps and Power Automate (Flow)


Hi Everyone,

This is my first post on Power Apps (Canvas App) and could be very basic to most of the people but it would helpful for the beginners like me.

  • Login to Make.PowerApps.Com
  • We can directly create an App and Flows from the navigation as below but I would recommend to create a Solution first and then create App and Flow in that.
  • Create a solution with the name as you wish and select the right publisher.
  • Open the solution and click on New from Top Navigation  --> App  --> Canvas App  --> Phone form factor(I have selected for it Phone UI for this post, you can select as per your requirement)
  • Save the App first with desired name. You can use Ctrl+S as a shortcut.
  • You will get the new tab in the browser as below.
  • From Insert Menu add required text boxes, labels and a button on the Screen. Make sure you use good naming convention as a best practice.
  • Go back to the solution again and create a flow as below.
  • Take trigger as PowerApps.
  • Declare two variables and set them to get the value from Power App. We have "Ask In Power Apps" in the value for getting the parameters.
  • Add a step to create a contact in Dynamics 365 CE using Common Data Service Connector and set the values. We cannot use Common Data Service Current Environment Connector as there is an OOB issue with that. Check this for more information on that.
  • Add "Respond to PowerApp or flow" and select response which you would like to send. Here I have selected Text and gave the response as below.
  • Let's go back to our canvas app and click on Action on top  --> Power Automate.
  • It will show the Flows that you have in the Organization and select the flow the one which you have created.
  • Call below OnSelect of the Create Contact button.

Set(flowResponse, NewContactCreatingFromFlow.Run(TextFirstname.Text, TextLastname.Text)); Notify(flowResponse.message,NotificationType.Success, 3000);

The code is simple, we are calling the flow with the parameters and storing the response in a variable called flowResponse. After the execution of flow is completed, we are notifying the user with the response that we got from Flow and for this we are using Notify command.

And Let's run it..


Hope this helps.

--
Happy 365'ing
Gopinath