Automating Business Process Flow Stage Transition with Power Automate
Business Process Flows
(BPFs) in Power Platform provide a visual guide to users as they navigate
through various stages in a process. Automating the transition between these
stages based on external events, such as an approval, can streamline and
enhance your business processes. In this blog post, we'll walk through a Power
Automate flow designed to achieve this, step by step.
Scenario Overview
Our scenario involves triggering a stage transition in a BPF when a specific condition is met. This condition is based on the outcome of an approval process.
Step-by-Step
Explanation
Step 1: Trigger
The flow starts when a
row is added, modified, or deleted in a CDS entity. The trigger is configured
to listen for changes in the 'new_request' entity, specifically
when the 'statuscode' equals 1 (assuming '1' represents a pending status).
Step 2: Get User
Record to send the Request
The flow retrieves the
details of the user associated with the record triggering the flow. This is
achieved by making a connection to the 'systemusers' entity in CDS and using
the user's ID from the triggering record.
Step 3: Start and
Wait for an Approval
An approval process is
initiated using the 'shared_approvals' connection. The details of the approval
include the title (subject of the record triggering the flow), assigned user
(from Step 2), and notification settings.
Step 4: Condition
A conditional check is
applied to determine the outcome of the approval. If the outcome is 'Approve,'
the flow proceeds to update the BPF stage; otherwise, it handles the rejection
case.
Step 5: Update BPF
Stage (Approve)
If the approval
outcome is 'Approve,' the flow updates the record status by making a connection to
the 'new_requests' entity and setting the 'statecode' to 1
(assuming '1' represents an active state) and 'statuscode' to 2.
Step 6: Update BPF
Stage (Reject)
In the case of rejection, the flow updates the record status by setting the 'statecode' to 1 and 'statuscode' to a custom rejection status code (e.g., '100000001').
Step 7: Get Current
Instance ID
This step retrieves
the current instance ID of the BPF associated with the triggering record. It
connects to the 'new_requesttovacancy' entity and filters based
on the 'new_request' from the triggering record.
Formula:
outputs('get_CurrentInstanceId')?['body/value']?[0]?['businessprocessflowinstanceid']
Step 8: Get Next
Stage ID by Using Stage Name
The flow retrieves the
process stage ID of the next stage in the BPF named 'Vacancy.' It queries the
'processstages' entity to find the stage with the specified name.
Step 9-10: Compose
Active and Next Stage ID
Compose actions are
used to create variables for the active stage ID and the next stage ID using
the outputs from the previous steps.
Active Stage Formula:
outputs('get_CurrentInstanceId')?['body/value']?[0]?['_activestageid_value']
Next Stage Formula:
outputs('get_NextStageId_by_using_Stage_Name')?['body/value']?[0]?['processstageid']
Step 11: Update BPF
Record Accordingly
This step updates the 'new_requesttovacancy' entity with the new active stage ID, related
Parameters:
- Entity Name: new_requesttovacancy
- The target entity in which the record
will be updated.
- This is the BPF Table Name
- Record ID:
- The specific record ID to be updated is
dynamically retrieved from the output of a previous step (get_CurrentInstanceId).
- This is the Current Instance ID
- Active Stage ID:
- The new active stage ID is retrieved
using the output from a previous step (get_NextStageId_by_using_Stage_Name)
and is bound to the 'processstages' entity.
- Formula: outputs('get_NextStageId_by_using_Stage_Name')?['body/value']?[0]?['processstageid']
- BPF Request ID:
- The recruitment requisition ID is obtained from the trigger outputs and is used to bind the record in the 'new_request' entity.
- Traversed Path:
- The traversed path is constructed using the active stage ID and next stage ID obtained from previous steps.
Step 7: Add a New
Row: Adding Notes to Timeline (Optional)
Irrespective of the
approval outcome, a note is added to the timeline using the 'annotations'
entity in CDS. The note includes details about the subject, approval comments,
and the user who initiated the approval.
Good post! We are linking to this great post on our website. Keep up the good writing. Thanks for sharing.
ReplyDeleteOffice 94fbr