Switch BPF using Power Automate

Switch BPF using Power Automate

1.Requirement:

Sometimes you need to switch a BPF based on some option set value. e.g. if I have an option set field named “Active BPF” in which I have one or more values. Based upon those values, going to switch BPF instance. Below are the trigger points.

  1. On creation of the case entity record.
  2. On update of an option set field on case entity form.

To achieve this functionality without using single line of code going to use Power Automate CDS Current Environment Connector. There is no solution available for achieving this functionality using Power Automate previously until I developed one. I am sharing my knowledge by which you can achieve the functionality using Power Automate.

3. Prerequisite:

  1. Dynamics 365 Customer Engagement Subscription.
  2. Power Automate Subscription.
  3. CDS Current Environment Subscription.

4.Resolution:

  1. Login to Power Apps with Dynamics 365 Organisation account URL-https://make.powerapps.com/.
  • Left pane you will found list of operation you can perform. Now click on Flows. Click on “+New” button and select Automated-from blank Flow.
  • Then give a proper name and select from the list of the trigger points available-Common Data Service Current Environment.

Trigger: – Create and Update of the Case Entity.

  • In filter attribute you can specify attribute as a part of trigger. e.g. Change of that attribute flow will run.
  • When a user clicks on create “+New” a new case entity record. Default BPF set to the record.

If there are 4 BPF active for case entity than based on their order, default BPF set (Top Order).

  • For setting a new BPF instance you need to delete or make it inactive. In this scenario I am deleting the default BPF instance and setting a new one.

Here Immigration BPF is default BPF. For Setting a new BPF (PWD Business Process Flow), need to delete existing or default BPF Instance.

  • Now let get back to the Flow. Now after the triggering point check the BPF option set value is null or not.

If it is not null,

check the value of the option set, suppose it is PWD BPF value 364840000, then delete the existing or default BPF (Immigration Business Process). For deleting the existing flow instance, need to perform several steps.

  • Get the process using List record CDS current environment action and add filter criteria (name eq ‘Immigration Business Process).
  • List records give you the collection of the record for get the all the data from the collection further we need to iterate the list of records using apply for each control. We need to get the instance of the Immigration Business Process Entity. Again, use the list record CDS Current Environment for getting the immigration business process flow entity instance record using filter query.

In the filter query “_bpf_incidentid_value” is an attribute in Immigration Business Process Entity, reference to the case record and processed/workflowid is Immigration Business Process Flow GUID. Set both values in filter attribute, now you have the record in response. Again, add apply for each control and add delete action of common data service current environment. Specify the entity name and item id is immigration business process entity instance record id.

After deletion of the default or existing process half of the task completed now we need to create the instance of the other business process – PWD Business Process.

  1. Here I am checking the “Active BPF” option set value in Case entity form using switch case condition.

Specify your Option set value.

Check the option set value is Posted Worker-36484000. If it matches than we need to follow some steps to create an instance of the flow and set it to case.

  1. List record process using CDS current environment Action and add filter query name eq ‘PWD Business Process’.
  1. Add apply for each and now we need the process stages of the PWD Business Process. Because while creating new PWD Business Process instance record we need to specify the active stage. In this scenario I am retrieving first Process Stage using filter query. In filter query I am filtering it based on process id which is PWD Business Process Guid and stage name is Case Validation (First stage in PWD BPF).

So now I have process stage. Next, create PWD Business Process Instance.

  1. Add a Apply for each condition it will give me the process stage entity record which I retrieved in previously. Inside it add an action “Create a Record” using CDS Current Environment. Specify the parameter as below.

1.Specify the Name – PWD Business Process

2.Active Stage (Process Stages)-/processstages(processstageid)

Processstages – Plural name of the entity and parameter will be entity guid which I am retrieving from the previous list record Process stages.

3.Incident (Cases) – /incidents(incidentid)

Incidents – Plural name of the case entity and parameter will be entity guid which I am retrieving from the trigger record.

4.Process (Processes)-/workflows(workflowid) pass the PWD BPF Guid.

5.Status Reason- Make status reason active.

It will create an instance of the PWD Business Process and set it to active. After that you need to update the case entity record.

  1. Select the new Action from the Common Data Service Current Environment- Update a Record. Give the entity name and the item id(from the trigger event), update the process id field by passing the PWD Business Process Instance Guid which created in previous step.

After that just terminate the flow.

Follow all the steps and you will be able to switch the BPF using Power Automate Common Data Service Current Environment Connector.

Author: Surya Pratap Singh

I am a Dynamics 365 Sales Functional Consultant Associate|MCSE|MCSA|MCP.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s