Archive
Power Automate Cloud Flow | ‘Correct to include a valid reference’ error
Other day while working on error handling scenario in my Cloud Flow, my Flow Checker given me following error.
Correct to include a valid reference to ‘Data Operation Divide‘ for the unput parameters(s) of action ‘Set_Error_Message‘.
Error from Flow checker
Lets see the reason and fix for this error.
Reason:
- In my flow, I am capturing the error message of my Compose action by name Data Operation Divide in my Set Variable action by name Set Error Message.
- My Data Operation Divide compose action does a simple division operation of ‘numA’ and ‘numB’ values using div function.
- My Set Error Message action configured to run only when Data Operation Divide compose action fails.
- Set Error Message action ‘Value’ configured with actions expression to read the Data Operation Divide action’s error.
- The expressions used is actions(‘Data Operation Divide‘)?[‘error’]?[‘message’]
- Everything does looks fine right?. Then where is the error?.
- The answer is actions expression does not accept spaces in the action name. In my case, action name is ‘Data Operation Divide‘ which has got spaces.
- Hence the ‘Flow Checker’ showing Correct to include a valid reference to ‘Data Operation Divide‘ for the unput parameters(s) of action ‘Set_Error_Message‘ error.
Fix:
- In the actions expression of Set Error Message action ‘Value’ parameter, replace spaces with underscore(_).
- Formula looks as below actions(‘Data_Operation_Divide‘)?[‘error’]?[‘message’]
- Notice the ‘Flow Checker’ and error is gone.
- Run the flow with ‘numA’ as 10 and ‘numB’ as 0.
- And the ‘Set_Error_Message‘ error action show the error message.
- So the bottom line, actions expression does not accept spaces in the action name.
Please refer my previous blog post with detailed explanation of error handling in Power automate flow.
🙂
[Step by Step] Create and call Global Custom API from Canvas App using Power Automate with Error Handling
In this article, lets learn how to create a Custom API and trigger using Power Automate Cloud Flow along with Error Handling from a Canvas App.
What is a Custom API:
- Using Custom APIs we can create our own APIs in Dataverse.
- We can consolidate one or more operations into a Custom API which can called from either code or from Power Automate.
- For example, you can create a Custom API called “OnBoardNewCustomer’, where you can have following operations.
- Create a new ‘Account’ record.
- Create a new ‘Appointment’ record scheduled a week from now.
- Send an Email notification.
Now lets get started with Custom API creation. I am going to use ‘Onboard Customer’ scenario to explain the Custom API creation. I will be using 2 operation in my Custom API.
- Create an Account record by reading ‘Name’ as input parameter.
- Create an Appointment record for the newly created Account and schedule at 7 days from now.
Create a Custom API:
There are several ways you can create a custom API documented here. In this article, I will be taking 2 step approach.
- Write a C# plugin class file with logic and register using Plugin Registration Tool (PRT).
- Create a Custom API using forms from Power Apps Maker portal and link the plugin created in previous step.
Steps to create Custom API in plugin class and register using PRT:
- Open Visual Studio and create a plug-in project as detailed in this document here.
- Add an .snk file to the project.
- Create a new plugin class file with logic to create Account and Customer.
- Final code in the class file looks as below.
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.MessageName.Equals("cat_onboardcustomer") && context.Stage.Equals(30))
{
try
{
// Read the input parameter
string inputParamCustomerName = (string)context.InputParameters["cat_customername"];
if (!string.IsNullOrEmpty(inputParamCustomerName))
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Create Account Record
var entAccount = new Entity("account");
entAccount["name"] = inputParamCustomerName;
var accountId = service.Create(entAccount);
// Create Appointment Record
var entAppointment = new Entity("appointment");
entAppointment["subject"] = $"Meeting with Customer {inputParamCustomerName}";
// Set the start and end times for the entAppointment 7 days fro now
entAppointment["scheduledstart"] = DateTime.Now.AddDays(7).AddHours(1);
entAppointment["scheduledend"] = DateTime.Now.AddDays(7).AddHours(2);
// Set the related account for the entAppointment
entAppointment["regardingobjectid"] = new EntityReference("account", accountId);
var appointmentId = service.Create(entAppointment);
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in cat_onboardcustomer.", ex);
}
}
}
- Build the project and register the plugin assembly using PRT.
- Post registration it should look as below from PRT.
Now that we completed the step 1 of creating and registering plug-in class file. Lets proceed with step 2 where we will create a Custom API entry.
Create a Custom API using forms from Power Apps Maker portal:
- Connect to Power Apps maker portal.
- Create a new solution or open any existing solution.
- Click on New -> More -> Other -> Custom API
- It opens up a new ‘Custom API’ form and fill the details.
- To understand the columns in depth, refer here.
- What is important for this example are:
- Unique Name : Unique name for the custom API. (Its cat_onboardcustomer we used in our plug-in class)
- Name : The primary name of the custom API.
- Plugin Type : Plugin we registered in previous section.
- Save and Close.
- As we need to pass a parameter to our ‘Custom API’, next add a new ‘Custom API Request Parameter’.
- Fill the details by selecting ‘Custom API’ we created in previous step and ‘Unique Name’ as cat_customername, which we used in our plugin class.
- Save and Close.
With this we successfully created ‘Custom API’ along with an input parameter. Lets see how to trigger API using Power Automate Cloud Flow from a Canvas App.
Steps to trigger Custom API from Canvas App:
- Create a new Canvas App.
- Go to Flows tab and click on ‘Create new flow’ and choose ‘Create from blank’.
- In the flow designer, add ‘Initialize Variable’ action and rename to ‘varCustomerName’. In the ‘Value’ select ‘Ask in PowerApps’.
- Next add Dataverse ‘Perform an unbound action‘ action which helps us to trigger our ‘Global’ custom API.
- Select ‘Action Name’ as our Custom API name cat_onboardcustomer
- In the cat_customername pass ‘Customer Name’ which was the variable declared in above step.
- If you dont want exception handling, you can save the flow which can trigger the cat_onboardcustomer.
Exception Handling:
Lets learn a basic error handling. Please note that you can use ‘Scope’ for more complex scenarios but for basic exception handling following process should suffice.
- Add another ‘Initialize Variable’ action and rename it to ‘varExceptionDetails’ and set Type as ‘String’.
- Rename the ‘Perform an unbound action’ to ‘InvokeOnboardAPI’
- Add a ‘Set Variable’ action ‘setExceptionDetails’ to capture the exception.
- Select the Name as ‘ExceptionDetails‘ and click on ‘Configure run after’. (This is needed as we want this ‘setExceptionDetails’ to execute even the above ‘InvokeOnboardAPI’ action fails or timeout.
- Select following options.
- In the ‘Value’ select ‘Expression’ and paste following expression.
- actions(‘InvokeOnboardAPI’)?[‘outputs’]?[‘body’]?[‘error’]
- Finally to send the response from flow to Canvas app, add ‘Respond to a PowerApp of flow’ action and click on ‘Configure run after’, select following options and click ‘Done’.
- and define an output variable OnboardflowResponse and set the value as ExceptionDetails.
- Save the flow and you should see the flow in your Canvas App.
- To trigger the flow, add a button to the screen and OnSelect write following formula.
Notify("Triggering User Onboard...");
UpdateContext({ResponseOnBoardFlow: CustomerOnboardFlow.Run("Rajeev Pentyala").onboardflowresponse});
If(
ResponseOnBoardFlow = "Success",
Notify("Customer onboarded successfully."),
Notify("Error while onboarding. Details - " & ResponseOnBoardFlow)
)
- Run the App and click the button.
- Open Dataverse and you should see the new Account and Appointment records. You can also check the flow run history.
🙂
Power Apps | Change App Owner using Power Automate Flow
Assume that you have a canvas app with Owner as ‘User 1’ and you would want to make ‘User 2’ as Owner of the App.
We have couple of options.
- Using Set-AdminPowerAppOwner command of PowerShell.
- Create a Power Automate Flow and trigger Set App Owner action of ‘Power Apps for Admins’ connector.
In this article lets see how to use Power Automate Flow to change the Owner. Following is how the completed flow looks like.

Key in this flow is ‘Set App Owner’ Action and following are the parameters.
Name | Key | Required | Type | Description |
---|---|---|---|---|
Environment Name | environment | True | string | Name field of the Environment. |
PowerApp Name | app | True | string | Name field of the PowerApp. |
API Version | api-version | string | The date value of the API version. | |
Content Type | Content-Type | string | The content type of the API request. | |
Role For Old App Owner | roleForOldAppOwner | string | The role name for the old app owner. Choose from CanView, CanViewWithShare, or CanEdit. | |
New PowerApp Owner | newAppOwner | string | The principal object ID of the new owner. |
Lets see step by step process to build the flow.
Step by Step budling flow:
- Create a new flow as shown below.
- As mentioned, key component of this flow is ‘Set App Owner’ Action and in the next steps, we will see how to pass parameters to ‘Set App Owner’ Action.
- First we need to capture the ‘New PowerApp Owner’ parameter which is ‘Principal object ID’ of the User.
- Note: ‘Principal object ID’ is not GUID of ‘System User’ in Dataverse. Its Azure Active Directory ID.
- Add a ‘Get user profile (V2)’ action of Office 365 Users connector to capture the ‘Principal object ID’ of the User.
- Rename the ‘Get user profile (V2)’ to ‘GetUserProfile’. (Optional Step)
- Set “User (UPN)” as the User Id of the new Owner.
- Now add ‘Set App Owner’ action.
- Set ‘New PowerApp Owner’ as ‘Id’ from the output of previous ‘GetUserProfile’ action.
- For ‘Environment Name‘ parameter, go to Power Apps maker portal, open ‘Settings -> Developer resources’.
- Copy ‘Environment ID’ and paste in ‘Environment Name‘ parameter of ‘Set App Owner’ action.
- For ‘PowerApp Name‘ parameter, go to Power Apps maker portal, open ‘App -> Details’.
- Copy the ‘App ID‘ and paste in ‘PowerApp Name’ parameter of ‘Set App Owner’ action.
- For ‘Role For Old App Owner‘ parameter, either you can leave or provide ‘CanView’.
- Leave ‘API Version‘ and ‘Content Type‘ as default.
- You should see the flow as below once you follow all mentioned steps.
- That’s all needed!. Run the flow and you should see the owner of the App to the new user mention in the flow.
🙂
Cloud flow | Dataverse Connector | Useful formulas and Syntaxes
In this article, I am going to collate useful Syntaxes and Formulas frequently used in Cloud Flows with Dataverse connector.
Format DateTime:
When working with date and time values in flow, they may look like:
- 2019-12-06T22:47:23.0798367Z or 2009-06-15T13:45:30Z
You may format these values to look like:
- 6/15/2009 1:45 PM or Monday, June 15, 2009
This is done by using Date and Time Format Strings passed to the formatDateTime() function.
Example: Following is the formula to convert the ‘CreatedOn’ to ‘MM/dd/yyyy’ format.
- ‘createdon’ has been retrieved from Flow’s ‘triggerBody()’.
Get Optionset/Choice Label:
- By default, ‘Optionset/Choice’ field gives the Value not Label.
- As an example, ‘Gender’ field (i.e., ‘pis_gender’) gives the ‘100000001’ not ‘Male’.
- To get the Label, read by _{field-schema-name}_label.
Set the Lookup value:
- To set Lookup field, in the Dataverse’s ‘Add a new row’ and ‘Update a row’ Actions, use following syntax.
- Entity/TableName(UniqueId)
- In below example, ‘pis_customers’ is my table name and reading ‘Customer ID’ from TriggerOutputs body.
- pis_customers(@{triggerOutputs()?[‘body/pis_customerid’]})
Read the Dataverse ‘Trigger Name’:
- If you have a Dataverse trigger with ‘Change type’ set as ‘Added or Modified or Deleted’.
- Following is the statement to read the ‘Message’ (i.e., Create or Update or Delete).
- @{triggerBody()?[‘sdkmessage’]}
Get Length of the Rows:
- In my flow, I’ve a ‘List rows’ Action which retrieves the ‘Cars’ records.
- To get the Count of the records, following is the syntax:
- @{length(outputs(‘GetAssociatedCars’)?[‘body/value’])}
🙂
[Step by Step] Dataverse | Connect Cloud flow with Service Principal (Application User)
By default, Cloud flow Dataverse connectors run under the Owner (i.e., User who created the flow) context. When the flows move to different environment via solutions, connectors run under the user account who imported the Solution.
Making the flows run under interactive user accounts is not recommended as they cause confusion when we check the record’s audit for who updated the record. Its recommended to make the flow run under ‘Application User’, if the calling user can be a fixed account.
In this article lets see how to make the flow run under Application User using Connect the flow using Service Principal option.
High level design:
Following are the steps we gonna go through.
- App registration in Azure Active Directory (AAD)
- Create an Application User in Environment.
- Create a Cloud Flow and connect with Application User.
App registration in Azure Active Directory (AAD)
- Connect to Azure Active Directory Admin Center.
- Create a new ‘App Registration’.
- Add a Secret and save the Secret.
- Copy the Application ID and Tenant ID.
- Refer this article for the detailed ‘App Registration’ steps.
Create an Application User in Environment
- Connect to Power Platform Admin Center.
- Open the Environment and click on ‘S2S Apps’ (S2S stands for Server to Server).
- Click on ‘New app user’ and select ‘Business Unit’ and ‘Security Role(s)’.
- Click on ‘Add an app’ and select the App registered in previous section.
- You should see the ‘Application user’ listed as below.
Create a Cloud Flow and connect with Application User:
- Connect to Maker portal and create a new Solution.
- Click on New -> Cloud flow.
- Click on ‘Connect with Service Principle’.
- Provide the details captured in Azure Active Directory ‘App Registration’ section and click ‘Create’.
- Now you should see that in ‘Connection references’ as below.
- If you go back to the ‘Solution’, you would see a new entry ‘Connection Reference (preview)’ along with the flow.
- With the ‘Connection Reference (preview)’, we can conveniently move flow to different environment using Solution export and import.
- Lets proceed and complete the flow, which creates a ‘Contact’ record upon the creation of an ‘Account’.
- Create an ‘Account’ from the ‘Customer Service Hub’ App.
- A ‘Contact’ gets created triggered from the flow and Owner would the ‘Application User’.
Notes:
- You can use ‘Run as’ option and make the ‘Dataverse’ run under one of the highlighted User contexts.
🙂
Power Platform – Pass external API collection from Power Automate to Canvas App
In this article, lets see how to pass an external API’s json collection from Power Automate(Formerly ‘Microsoft Flow’) to a Canvas application.
For this example, I am going to use ESRI mapping service API, in my Power Automate Flow. Refer here to know more about ESRI. You may also use other APIs as per your convenience.
ESRI API is url based and returns the ‘Address Suggestions’ in json format.
Before we start lets make sure to meet all the prerequisites.
Prerequisites:
- Subscribe to 30 days trial and get Office 365 account.
- Connect to Power Automate portal using Office 365 account to build Power Automate flow.
- Connect to Power Apps maker portal using Office 365 account to build the Canvas App.
- ESRI api URL – Refer my previous article on the usage of ESRI or you can simply use this url
Once all prerequisites are met, here is the high level design:
- Create a new Power Automate flow and call ESRI API to fetch Address Suggestions.
- You can take any open API which returns json collection.
- Parse the ESRI API Response to json collection.
- Create a new Canvas app
- Trigger Power automate flow from Canvas App and read the collection.
Lets get started.
Steps to configure the Power Automate Flow:
- Connect to Power Automate portal
- Create a new ‘Instant flow’ by selecting the right Environment.
- Provide a name ‘GetAddressSuggestions’ and select trigger as ‘PowerApps’
- To call ESRI api, add a new ‘HTTP’ action.
- Choose Method as ‘GET’ and in URI paste the ESRI url as mentioned in prerequisite section.
- Next, we need to parse the response from ESRI api. As the ESRI results would be in json format, add ‘Parse JSON’ action.
- In ‘Parse JSON’ action,
- set Content as ‘Body’ from HTTP action.
- Next we need to provide the json schema of ESRI response. To do that, click on ‘Generate from sample’.
- Now copy the response from ESRI API (Copy the browser’s output using ctrl+a+copy)
- Paste in the ‘Insert a sample JSON Payload’ window and click ‘Done’.
- If no warnings, your ‘Parse JSON’ pane should look as below.
- As we completed the ESRI response capture and parsing to json, now we need to pass the captured json response to Power App.
- To pass the json response to Power App, add a new ‘Response’ action.
- In the ‘Response’ pane,
- Set the ‘Body’ to ‘Body’ from ‘Parse JSON’.
- Expand ‘Show advanced options’ and click on ‘Generate from sample’.
- Copy the response from ESRI API and paste in the ‘Insert a sample JSON Payload’ window and click ‘Done’. (Same step like we did in ‘Parse JSON’ pane).
- ‘Response’ pane should look as below with no warnings.
- Run the flow and make sure it ran successfully.
Steps to configure the Canvas App:
As we completed the Power Auto Flow, now its time to consume the Power Automate flow response from Canvas App by following the steps below
- Connect to Power Apps maker portal using the same Office 365 account.
- Create a new Canvas App.
- Note: Make sure the same Environment used for Power Automate is selected.
- Add a new button.
- Select the button, from the ribbon menu, click on ‘Action -> Power Automate’.
- From the pane select the ‘GetAddressSuggestions’ Power app flow.
- After few seconds, you would see the Run() command auto populated as below.
- As we going to get json collection from flow, lets capture the json collection to a collection variable ‘collAddress’ using ‘ClearCollect()’. Refer article to know more about ‘ClearCollect()’.
- With the ClearCollect() and Run() functions, the final ‘OnSelect’ statement should look as below.
- Lets run the App and click on the button. Application takes couple of minutes to complete the run.
- Post run, check the collection returned from flow by going to ‘File -> Collections’ tab.
- You can also add a ‘Data table’ control and display the results returned from flow as below
🙂