Model driven apps
Get record and business process flow information in Power Automate flow step of Business process flow in Dynamics 365/ CDS
Category: CDS,Dynamics 365,Execute power automate flow in Business process flow step.,Model driven apps Author: debajit prod Date: 3 weeks ago Comments: 0

Are you having any of the following requirements?

  • You have configured a Power Automate flow to execute as Business process flow step and want to access the record which is displaying the business process flow.
  • You want to work with the Business process flow instance and take decisions based on the stage the record is currently in.

If you are having this requirement, you are not alone. Since the time Microsoft have released the capability to execute a flow as a Business process flow step in Dynamics 365/ CDS, customers and consultants alike are exploring the various possibilities on how this feature can be leveraged. And more often that not you require to access either the BPF instance or the record data from which the flow is currently executing.

While there are quite a few examples on how to execute a flow step from Business process flow, we need to understand how the flow will have access to the record and BPF instance. So let’s get started.

For this demo, I will create a simple leave request flow that the requestor will click to send an email to the approver with the leave request information.

The first and foremost thing that you should remember here is – “Any flow you intend to use as a flow step in Business process flow must be created within a solution. Otherwise the flow won’t be available for selection when you try to add the flow in the Business process step.

Select Common Data Service connector and then select – “When a record is selected” trigger. Observe I haven’t used the Common data service (current environment) connector as it does not have the trigger we are looking for.

When a record is selected -  Power Automate.

This is probably the most important step. I come across lots of examples which uses the “Manually run a flow trigger”. The whole agenda here is to pass the Business process flow and the record information to the flow. And for that it is essential that you use this trigger.

You might be wondering, when does this flow fire? What record should I select to trigger the flow? Whenever you are executing the Power Automate flow from Business process flow, the flow shall trigger. And the record context will be the Business process flow instance. Hence I configure the Power Automate flow as below. “Leave approval process flow” is my business process flow entity.

BPF - Flow step.

The next step is to fetch the Leave request record. For that I use the Common data service (current environment) connector and use the GetRecord action. But this is where it may get bit challenging. While we expect the output from the previous step as an entity of type “Leave approval process flow”, the final content is basically generic business process flow entity schema. If you run the flow you will see the below output.

"body": {
        "entity": {
            "entity": {
                "FlowsWorkflowLogId": "0299a4cf-56ab-4349-b6ea-00f4514a385d",
                "BPFInstanceId": "6d65e7cc-39fe-ea11-a815-002248049354",
                "BPFInstanceEntityName": "contoso_leaveapprovalprocessflow",
                "BPFDefinitionId": "1a19ef4d-a685-4676-8a6a-f2d988c3a280",
                "BPFDefinitionEntityName": "workflow",
                "StepId": "0492a8a7-6776-41ee-bfdf-46ad7be3e796",
                "BPFDefinitionName": "Leave Approval Process Flow",
                "BPFInstanceName": "Leave Approval Process Flow",
                "BPFFlowStageLocalizedName": "Apply",
                "BPFFlowStageEntityName": "contoso_leaverequest",
                "BPFFlowStageEntityCollectionName": "contoso_leaverequests",
                "BPFFlowStageEntityRecordId": "7719d0bd-b73a-4e4f-8845-4626d1078d90",
                "BPFActiveStageId": "fda8c64a-9269-446c-9988-eff5a6544839",
                "BPFActiveStageEntityName": "processstage",
                "BPFActiveStageLocalizedName": "Apply"
            }
        }
    }

While this may bog you down, you need “BPFFlowStageEntityRecordId” which is basically the GUID of the entity record. And how to get it? Quite easy. I use the “Get a record” action of Common data service (current environment) connector. In the Item ID, I use the below expression.

triggerBody()['entity']['entity']['BPFFlowStageEntityRecordId']
Business process flow - Flow step.

We have done the hard part already. We now have the Leave Request record information and the Business process flow instance record information. To complete the whole process, I send an email to the approver. Below is the screenshot of the whole flow in action.

Business process flow - Flow step.

The final piece in the puzzle is to use the flow we just created in the Business process flow step.

Business process flow - Flow step.

Once you update your business process flow and the requestor clicks on the Run flow button, our beloved flow fires.

Run flow from Business process flow.

And you should see our flow running successfully.

Run flow from Business process flow.

Hope this helps!

You may also like the below posts

Debajit Dutta
(Business Solutions MVP)

Source: Debajit


Query related entity data in CDS using FetchXml in Power Automate
Category: Dynamics 365,Fetchxml in Power Automate,Model driven apps,Power Automate Author: debajit prod Date: 4 weeks ago Comments: 0
  • How do I use FetchXml in Power Automate?
  • How do I access related entity fields when using Fetchxml in PowerAutomate?

If you are having any of the above questions, you are at the right place. Strictly speaking, this blog is more about how to access related entity information in PowerAutomate through FetchXml. But as I am going to explain from the beginning, if you are not aware of the basics as well, this blog might help you with that too.

To demo this scenario, I am using the below fetchxml.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="parentcustomerid" />
    <attribute name="emailaddress1" />
    <attribute name="contactid" />
    <order attribute="fullname" descending="false" />
    <filter type="and">
      <condition attribute="statecode" operator="eq" value="0" />
      <condition attribute="parentcustomerid" operator="eq" value="{B56B3F4B-1BE7-E611-8101-E0071B6AF231}" />
    </filter>
    <link-entity name="account" from="accountid" to="parentcustomerid" visible="false" link-type="outer" alias="pa">
      <attribute name="address1_composite" />
 <!-- string field -->
      <attribute name="industrycode" />
 <!-- optionset field -->
    </link-entity>
  </entity>
</fetch>

Quite evident from the above fetchxml, I am retrieving all the contacts associated with an account. For the account record, I am retrieving the value of “Address 1” field which is of type text and “Industry” field which is of type optionset. Also note the alias – “pa” I am using while I join with the account entity. And below is my Power Automate flow.

Power Automate FetchXml
Power Automate FetchXml

Quite a simple flow nonetheless. Below are the steps for the flow.

  • Declare couple of variables to store the Account Address and Industry
  • Run the fetchxml
  • Iterate through the items returned by FetchXml and set the value of Account address and industry.

You might be thinking, it’s quite a mundane one. And to be honest it is. But what does baffle infact a lot is your related entity data (in this case for account entity) does not show up in the Dynamic content pane of Power Automate flow.

Dynamic content - Power Automate Flow
Dynamic content – Power Automate Flow

Then how do I get it. It’s actually quite easy. Just select any placeholder value from Dynamic content pane and then from the side menu (ellipsis), choose “Peek Code“.

Peek code Power Automate
Peek code Power Automate

Copy the expression that you see in the value

Peek code Power Automate

Now to get the Industry code all we need to do is use the appropriate field names in the expression. Below are the expressions for Industry code and Address 1 fields.

Industry - items('Apply_to_each')?['pa.industrycode']
Address 1 - items('Apply_to_each')?['pa.address1_composite']
Variables - Power Automate Flow
Variables – Power Automate Flow

As you can see, I now have the correct values. Or is it? There is a small glitch though. The Account Industry is showing as 5 instead of name. That is because it is Optionset and if you put the field name in the expression, it will always give you the optionset value. If you want the Optionset text you need to use the below expression.

items('Apply_to_each')?['pa.industrycode@OData.Community.Display.V1.FormattedValue']

Very much similar to the format we use to retrieve optionset text using WebApi.

Hope this helps!

You may also like the below posts

Debajit Dutta
(Business Solutions MVP)

Source: Debajit


Configure Model Driven App Visibility
Category: Configure security roles for Model driven app,Dynamics 365,Dynamics 365 CE Online,Make model driven app visible to non admin users,Model driven app is not visible to user,Model driven app permission,Model driven apps,Power Apps,Power Platform Author: HIMBAP Date: 3 months ago Comments: 0

Introduction This article is about configuring security of model driven app, you can refer details section to make your custom app visible to other users. Details When a new model driven app is created only System Administrator and System Customizer have access to the app. In order to provide access to new app to other users we need to make… Read more »
Source: Mahendra Pal


Resource not found for segment–Error with Common Data Service (Current Environment) connector in Power Automate/ Microsoft Flow
Category: CDS,Dynamics 365,Error during setting regarding field,Microsoft Flow,Model driven apps,Power Automate,Resource not found for segment Author: Debajit Dutta Date: 3 months ago Comments: 0

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 This one was pretty surprising and today I faced this error while trying to implement the most mundane operation with Power Automate. On create of an Account, depending on the Account Category, I […]
Source: Debajit


Upload content to File Attribute in Dynamics 365/ CDS from JavaScript
Category: CDS,Dynamics 365,File attribute content in Dynamics 365,JavaScript,Microsoft CRM,Microsoft Dynamics CRM,Model driven apps Author: Debajit Dutta Date: 3 months ago Comments: 0

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 This has been a long ask from my readers since the time I wrote the blog on how to read contents of File attribute using JavaScript in Dynamics 365. So here I am … Continue reading Upload content to File Attribute in Dynamics 365/ CDS from JavaScript
Source: Debajit


Dynamics 365 Online Sql Query To CDS
Category: CDS,Dynamics 365,Model driven apps,Query CDS database using C# Author: Debajit Dutta Date: 3 months ago Comments: 0

Originally posted on xrm CRM Dynamics:
Recently Microsoft has released new product feature where we can directly connect to SQL and write query into CSD Database. Currently this is in preview and not recommended for Product environment. This feature will only allow you to perform Read only operations, it does not allow to perfrom DDL…
Source: Debajit


Custom Button on Dashboard not displayed in Dynamics 365 UCI
Category: CDS,Custom button on Dashboard not showing in Dynamics 365,Dynamics 365,Microsoft CRM,Microsoft Dynamics CRM,Model driven apps Author: Debajit Dutta Date: 3 months ago Comments: 0

Originally posted on Helplessheroes:
It is observed that custom ribbon buttons don’t show up in unified interface, to solve this issue follow below steps. Install chrome extension to execute REST calls: • Open Chrome Webstore• Look for extension Yet Another Rest Client and add it to your chrome browser.• Open and login to your Dynamics…
Source: Debajit


1 2 3 7