Dynamics 365 Project Service Automation: Two-tier Time Entry approvals with Flow

Tested on:
Dynamics 365 version 9.0.2, PSA solution version 3.x, Unified Interface, Microsoft Flow

Time and Expense Entries and their approvals are an important part of Dynamics 365 Project Service Automation. A slight downside to Project Approvals is that the logic is based on a single level approval process: A user (or users) set as a Project Approver under Project Team Members approves all Time and Expense Entries related to a Project. But what if a manager’s approval is needed before a Project Approver signs off on submitted hours? To achieve this, we’re using Microsoft Flow to build a two-tier approval process.

Before I start going through the solution, I want to point out some very good Microsoft Flow posts from the community. These help you understand some of the steps in my solution and they’ll also shed some light on the differences between the D365 and CDS connectors in Flow etc. Be sure to check these out:

    1. Microsoft Flow basics and limitations when working with Dynamics 365 by Thanura Wijesiriwardena.
    2. Microsoft Flow Approval Workflow by Senior Platform Evangelist Jon Levesque.
    3. What The Flow series by Business Applications MVP Elaiza Benitez.

Out of the box functionality

The OOTB functionality for approving Time and Expense Entries is as follows:

  • A user is set as a Project Approver on Project Team Members. That user will then be able to approve all Time and Expense Entries related to the Project.
  • A user submits Time/Expense Entries -> Journal Lines are created -> a Project Approval record is created.
  • A Project Approver approves the submitted entries -> Actuals are created.
    • If the entries are rejected, the submitter will see the related entries as “Returned” on the Time Entry entity.

Building a solution for two-tier Time Entry approvals

The initial approval in this solution will be based on Flow and the second, final approval, will leverage PSA’s OOTB functionality. As Actuals are created when a Time/Expense Entry is approved, meddling with the OOTB logic is inadvisable. Instead, additional logic can be built around the OOTB functionality to extend PSA’s capabilities.

Remember that this is a single example of extending Project Approvals and that approval Flows only work with internal users. There are other ways to approach this issue as well as some organizations may require an approval process that has more than two tiers.

1. Fields on Bookable Resource

The following three custom fields are added on Bookable Resource:

  • User’s Email. Value from this field will be passed to Project Approval to serve as a Requestor in an approval Flow.
  • Manager. Value from this field will be passed to Project Approval to indicate the manager who will be responsible for the initial approval stage.
  • Manager’s Email. Value from this field will be passed to Project Approval. An approval Flow will then use the value from this field on the Flow’s Assigned to field.

Vacation and Absence approvals in PSA are always approved by a manager defined under a user record (Settings -> Security -> Users). As this manager might differ from the one approving project related work, custom fields on Bookable Resource are needed.

2. Views and fields on Project Approval

Project Approval has a custom view for a manager approving entries. Some custom fields are also required so that the approval process can be properly run. Remember that first we are getting an approval by a manager, followed by PSA’s OOTB approval process by a Project Team Member set as a Project Approver. The custom fields on Project Approval are:

  • Time Entry Type. This indicates whether an entry is for Work, Vacation or Absence. Only Work will fire off an approval Flow as in PSA. Absence and Vacation will be approved by a manager defined under a user record.
  • Submitter’s Email. Value from this field will be used in an approval Flow’s Requestor field.
  • Manager for Approval. Used to indicate the manager who will be responsible for the initial approval stage.
  • Manager’s Email. An approval Flow will use the value from this field on the Flow’s Assigned to field.
  • Approved by Manager. Values are Pending, Yes and No. Only records that have a value of Yes on this field can be approved from the ribbon’s Approve button.
  • Manager’s Comments. Comments written by a manager to an approval email will be seen on this field.

3. Real-time workflows for Project Approval

A real-time workflow is needed to prevent a Project Approver from approving entries that have not yet gone through the initial approval. A workflow gives an error message if the initial approval is not complete. A second workflow is used to pull values from the custom fields on Bookable Resource to Project Approval. The approval Flow has a condition that checks the values of Time Entry Type, Manager’s Email and Approved by Manager. To get the condition working, a real-time workflow updates the fields on Project Approval.

Prevent entry approval before initial approval is processed.

Update Project Approval from Bookable Resource.

4. Time Entry approval Flow

Now that the required fields, views and real-time workflows are ready, we can build the actual approval Flow. Check out the three links I mentioned earlier if you want additional ideas around connectors, expressions and if your scenario requires several approval tiers. For this Flow the condition to fire off an approval is:

@and(equals(triggerBody()?[‘cust_approvedbymanagerc’], 832090002),
equals(triggerBody()?[‘cust_timeentrytype’], 192350000),
equals(empty(triggerBody()?[‘cust_managersemailc’]), false))

In plain English:

If Approved by Manager = Pending
AND
Time Entry Type = Work
AND
Manager’s Email contains data
–> fire off the approval process

5. Testing the Flow

Let’s test the Flow by both approving and rejecting a submitter’s Time Entries. I’m submitting Time Entries as John Doe. His manager is Jane Doe.

Approving Time Entries

The approval process is fired off as all conditions are met.

Jane Doe receives an email to approve John Doe’s Time Entries.

A push notification is also sent as the Flow mobile app is installed. Time Entries can be approved either from the mobile app or from the email message.

The Flow has run successfully and the entries have been approved by the manager – Jane Doe.

As the entries have been approved, the field Approved by Manager has a value of Yes. Jane Doe’s comments, inserted at approval, are also visible on the Project Approval record. The Time Entry can now be approved from the ribbon by a Project Approver.
Rejecting Time Entries

These entries will be rejected.

Jane Doe has rejected these entries as the manager of John Doe. When attempting to approve the entry from the Project Approval record’s ribbon, an error is given as Approved by Manager has a value of No.

I hope this post helps you implement an additional layer of approvals for Time and Expense Entries in Dynamics 365 Project Service Automation. If you want to download the managed solution and the Flow, you can get them from the Those Dynamics Guys PowerApps Bank here.

Disclaimer:
All my blog posts reflect my personal opinions and findings unless otherwise stated.

1 thought on “Dynamics 365 Project Service Automation: Two-tier Time Entry approvals with Flow”

Leave a Reply

Your email address will not be published. Required fields are marked *