Project for the web is Microsoft’s most recent offering for cloud-based work and project management. It’s built on top of Common Data Service (CDS), which opens a lot of possibilities when working with Microsoft’s new chapter of project management software. One of the scenarios made possible by CDS and the Power platform is building robust workflows, using modern tools and no code.
This post will go through creating an automated approval workflow for projects using Flow.
A project follows a 3-stage workflow (Create, Select, Manage), and we want to require an approval when arriving at the second stage, then move automatically to the 3rd stage upon approval.
In the workflow pictured below, an approval task will be generated when the project reaches “Select” stage. Once the project is approved, it will automatically advance to “Manage”
The 3 stages of the project will be implemented as a Business Project Flow, which we’ll call “Project Flow”.
A separate Flow will be created for the “Project Flow” entity. This flow will be triggered when the active stage of “Project Flow” changes. When a project reaches “Select”, an approval task will be generated. The flow will then change the active stage once the approval passes. The Select stage will also have a security-enabled mandatory field that regular users cannot fill in, which will be completed by the flow upon approval, so that the project cannot be moved forward without approval.
Security Enabled Field
As a preparation step, we need to create a security enabled field that will be set as mandatory for our approval stage, but a regular user will not be able to update. Our flow will instead update this field only once the approval passes. The field will be part of the “Project” entity.
We’ll call the field “Approved” and we’ll have it as an Option Set field, with possible values Yes or No (although we’ll only use “Yes” in this example).
Details on how to create a new field can be found here.
Details for how to set up field level security in Dynamics 365 can be found here.
In order to use a dynamic approver, we’ll create a Project field named “Approver”, with the following setup
This field will be used to select the approver of a project.
Business Process Flow
The user-facing part of the workflow containing the 3 stages will be a Business Project Flow which we are naming “Project Flow”.
The first stage, “Create”, will contain one Data Step, set to Approver, which will be required.
Users will not be able to advance to the next workflow stage (Select) before filling in an approver.
Once an approver is filled in, the project can be advanced to Select
The Select Stage will contain one Data Step, using Approved as a required field
Since Approved is security enabled and the current user does not have permissions to edit its value, and it’s required for the stage, the current user cannot advance the Business Process Flow any further.
Our 3rd stage, Manage, does not have any special logic attached.
Power Automate Flow
Behind the scenes, we’ll have a Power Automate Flow which we are naming “Automatic Approval Flow”.
The flow will be triggered by a change of the active stage on the “Project Flow” entity (the Business Process Flow described above).
In the next step, our flow will use a “Get record” action for Common Data Service to read the project that the current BPF instance relates to.
Next, another “Get record” step will read information about the active stage of Project Flow.
We will then create a variable named “ManageStageID”, which will be used later to advance the workflow to the 3rd stage of the workflow.
Next, the flow will check the name of the stage through a condition set to “Process Stage Name” equals Select
At this point, we are only taking additional actions in the flow if this condition is met, meaning the “No” branch of this condition is empty, and the flow will be completed if the current stage is other than Select.
If the current stage is Select, we are reading the value of the Approver field set for the project using another “Get record” action.
At this point, the flow will create an approval task using the “Start and wait for an approval” action.
In the approval action, we will use a few dynamic values:
- Name of the project, from the GetProject action
- PrimaryEmail of the approver, from the GetApprover action
- Process Stage Name from the GetStage action
When the flow runs and reaches this point, an email similar to the below will be sent to the selected Approver
When clicking on “Approve” in the email, the following dialog will display in a browser
After confirming the approval, the outcome of the flow approval will be “Approve”.
Before checking for the approval outcome, our flow will use a “Get record” action to read information for the “Project Manager” field for the current project, to use in an email notification that informs the PM of the approval outcome.
Our flow will then check the outcome of the approval
If the outcome is no “Approve”, then an email is sent to the Project Manager and the flow is completed.
If the project is approved, the flow will update the value for the Approved field to “Yes” through an “Update record” Common Data Service action
Next, we need to find the ID of the stage we want to move the project to, “Manage”. For that, we are using a “List records” Common Data Service action to get stages named “Manage”
For simplicity, we’ll assume the above list contains only one record and we’ll assign the stage ID (Process Stage) to the ManageStageID variable defined earlier.
Next, we are updating the active stage through an “Update Record” activity.
And we wend an email to the Project Manager informing them that the project was approved
If we look back at the project, we’ll find it in the Manage stage