Dynamics 365 Project Service Automation: Creating a Project with Power Virtual Agents

Power Virtual Agents is definitely a hot topic as I’m writing this blog post. It’s a pretty easy tool to use and definitely a lot of fun. My idea for this post was to create a project in Project for the web by using PVA’s bot as a project template builder. However due to some current limitations with some of Project for the web’s entities, I had to switch my tool from P4W to D365 PSA. The idea is pretty much the same whether P4W or PSA is used: When a user creates a project, PVA’s bot runs the user through a series of questions so that the desired project gets created just right.

Before you read on, I do want to point out that this point isn’t a 101 on how to get started with PVA. I’ll list some links down the line to help you crack some of the more time consuming issues.

What does it take to get started with PVA?

The authoring canvas of PVA is a simple to use point&click experience. PVA just went GA so expect to run into scenarios where the authoring experience will feel limited as the product is still very new. Feedback is key in improving Microsoft’s SaaS offering so be sure to post you feedback here.

Authentication is something that you will most likely run into pretty fast. There are great guides in the community to get tips and tricks around getting authentication working. As you’re getting started with PVA, that is something that you will probably spend a bit of time figuring out. I read though this post by MVP Tomasz Poszytek and watched an insightful vlog by MVP Natraj Yegnaraman. Those sources should get you started with authentication.

Power Automate is naturally at the very center of PVA. It’s something that can pretty easily take the biggest chunk of your time when creating a PVA bot. You should have at least some experience with Power Automate and understand the basics of JSON to get started.

Authentication in Project Bot

PVA bots are built on an authoring canvas experience. In the Project Bot I’ve created, the first steps are around authentication to get our hands on a User Principal Name (UPN) and id of the user creating a new project. When a user is authenticated, the project creation process moves forward. Before we move on let’s, look at the authentication Flow.

Authentication in the Project Bot.

The authentication Flow is pretty straightforward. A token form the authentication process is passed to the Flow. An HTTP GET action is then used to get the UPN and id of the authenticated user. These values are then passed back to the Project Bot in Power Virtual Agents.

Authentication Flow.

Creating a new Project with the Project Bot

Creating a project undeniably takes a bit of time with the Project Bot. There are quite a few pieces of information that need to be collected so that a project can be created. It would probably be faster to create a project straight in PSA’s model-driven app, but speed is beside the point. What I’ve wanted to do with the Project Bot is to illustrate what is possible with Power Virtual Agents, instead of focusing on how fast it’s possible to create a project in PSA. With this in mind, let’s cover the questions that the Project Bot will ask when creating a new project.

The process of creating a new project starts with the Project Bot asking what kind of project a user wants to create. For this example the only option is Small Consultancy. There is an important point to this though: As we progress to the Flow that is used to create a new project, the type of project that will be created will be based on the selection made in this first step. A value of a predefined PSA’s Project Template will be used to create a project based on the initial selection.

The next question a user is faced with is about the length of the project. In this example, Small Consultancy projects can be max 20 man days. Choosing a length that is greater than 20 will restart the topic. Choosing a value that is less than 3 will also produce an error. In this example, projects under 3 man days are too small. The user can either end the session with the Project Bot or restart it. Values between 3 and 20 will take the dialog further and the Project Bot will ask the user for both the project’s name and the account that the project is for. Next up is the Flow that creates the project.

Creating a new project with the Project Bot.

The input parameters of the Flow are based on the answers to the previous questions that the Project Bot asks. In this example, the Flow’s output parameters contain much of the same values as the input parameters do. This is merely due to some last minute design changes that I made.

There’s one variable in the output parameters that is particularly important. It’s the output named flow_output_listaccounts. If the value of the output equals true, a project is created. If the value of the output equals false, it means that the account name that the user typed in the Projct Bot’s previous question is not found in Dynamics 365. The user is given a choice to either end the session or type the account name again. If the name is correct, a project is created. If the account name is still false, the Project Bot gets frustrated and snappy and tells the user to check the account name in D365. The bot then ends the session. As I’m the only person using the Project Bot, I took the liberty of making the bot snappy and gave it some character.

The final steps in the Project Bot.

Let’s look at the Flow that creates a new project. The variables at the beginning of the Flow get their values from the input parameters. The only exception to this is the VarListAccounts variable. Its value is set based on the output of the List Accounts action.

Variables in Flow.

If the output of List Accounts doesn’t return an account, the VarListAccounts will be set to false. This value will then be passed on to PVA so that the user can try to enter the account name again (alternatively, the session will end if a second attempt to enter the account name fails).

When List Accounts returns a value, a project is created. To set the user as the project’s Project Manager, we need to get our hands on the GUID for the user’s Bookable Resource record. To get that, we first need the systemuserid of the user. Note that the id that we have gotten from the first authentication Flow is the value for azureactivedirectoryobjectid.

A compose action is used to compose the account name of the first record that the List Accounts action returns. As only a single record should be returned (let’s assume duplicate account names do not exist in D365), an Apply to Each loop can be avoided by using a simple expression:
first(body(‘List_Accounts’)?[‘value’]). accountid

The Scope – Project actions scope contains all the relevant actions that actually create the project. As you can see from the Create a new Project action, there are quite a few details that we need to know for a project to be created. The value for Project Template will match a template that goes in line with the chosen option of creating a Small Consultancy project. The final action in the Flow passes values back to PVA.

Actions for creating a new project and the Flow’s response to PVA.

Project Bot and Teams

What would the Project Bot be without a home that makes it possible for users to interact with the bot. As this bot is for internal use only, Teams is the perfect home for it. Microsoft has pretty good instructions on adding a PVA bot to teams. To get started, read this article on docs.microsoft.com.

Project Bot in Teams.
Disclaimer:
All my blog posts reflect my personal opinions and findings unless otherwise stated.

Leave a Reply

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