top of page

HOW TO ADVANCE YOUR BUSINESS PROCESS FLOWS WITH CODE (PART II).

There are several ways to advance your Business Process Flows (BPF) in an automated manner: server-side or client-side. In the first part of the blog, we were able to see how to advance it on the client-side using JavaScript, and now we will see how to advance it using Power Automate.


Advancing the BPF on the server-side.


To do this within the environment of our solution, we will create a cloud flow.



Following the example from the first part of the blog, we will advance the BPF when the record is created and when the "mar_stage" field is changed. Then, we will simply incorporate the GUIDs of the BPF stages.


To obtain these GUIDs, you will need to execute the following in a browser window:

https://org.crm4.dynamics.com/api/data/v9.0/processstages?$select=stagename&$filter=processid/workflowid eq <processID>

Substituting the highlighted fields with our own, this will display the following:


{
"@odata.context":"https://org.crm4.dynamics.com/api/data/v9.0/$metadata#processstages(stagename)",
   "value":[
       {
           "@odata.etag":"W/\"761116\"",
           "stagename":"Stage 4",
           "processstageid":"73df2774-b083-4325-9804-845186962671"
       },
       {
           "@odata.etag":"W/\"761118\"",
           "stagename":"Stage 1",
           "processstageid":"7da32b9a-6994-ff0b-0cdc-b9c0c3bde713"
       },
       {
           "@odata.etag":"W/\"761112\"",
           "stagename":"Stage 2",
           "processstageid":"5148b38e-5fcd-4459-98e2-c778710192dd"
       },
       {
           "@odata.etag":"W/\"761114\"",
           "stagename":"Stage 3",
           "processstageid":"97b24b6c-0ac6-4d7d-8388-f47fec8af6fc"
       }
    ]
}

In this code, we will find the GUIDs of the stages that we will have in the BPF in order to prepare our automations and make the process progress.


We will incorporate these GUIDs into compose actions or variables.


The next step is to obtain the related BPF for the record that we will obtain in the trigger. To do this, we will incorporate the "List rows" action and filter by the GUID of the trigger record.

_bpf_mar_expedienteid_value eq RecordID

Next, we will use the "Parse JSON" action to retrieve the values of the tags from the output of this action. The output is an array, so in the "Content" field of the "Parse JSON" action, we will add the following expression to prevent it from adding an "Apply to each" loop since we expect only one BPF per record.


first(outputs('Get_BPF')?['body/value']) 

To generate the schema with the output of the "Get_BPF" action, you can follow these steps:



In the following image, we can see the actions commented on so far.



Finally, we will need to create a switch statement, similar to what we did in code in Part I of the blog, but this time using Power Automate.




With a "Compose" action and the following expression that concatenates the value of the current traversedpath of the process and the GUID of the stage, we will compose the new traversedpath based on the value of the "mar_stage" field.


concat(body('Análisis_del_archivo_JSON')?['traversedpath'],',',outputs('Stage_1_ID'))

It is important that at the end, we update the table of our BPF to advance this process, indicating in the record identifier (Row ID) the value of the "businessprocessflowinstanceid" obtained from the "Parse JSON" action.


As a recommendation, at the end of the process, you can incorporate an action that completes the BPF and deactivates the record. If it is an Opportunity in Dynamics 365, you can create a closing activity for the Opportunity.

Comentarios


bottom of page