Dynamics 365 projects usually contains connections between entities, that might not be connected out-of-the-box or there is no point of connection them directly, since the data model does not need it. There is need to have a connection between entities because customer needs. I was helping in a project using D365 Project Operations module and there was need to automate the connections with Project metadata.
Here is example how to automate the connections meaning creating the connection rows and connection roles rows with Power Automate flow. This example will cover situations when creation project and setting a project manger or customer and updating a project with these values. It will update the existing connection records or create ones if there was not created. This example also includes removing existing connections i.e. if customer value is removed from the project (since it is not required field like project manger).
Fields missing on create event
The first issue was that I could not create separate trigger for Created event, because the fields customer and project manager did not exist. I tried to reproduce the issue, but below picture says the opposite.

When changing the Change type to Added or Modified it allows you to save the flow. This means that I cannot do two separate Power Automates for create and update method, I need to handle all in one flow. This could be efficient or needs extra work if for example we cannot lock project manager or customer after creation. In this example it is possible to change them and this Power Automate flow will also update the changed values to the connection records.

When reproducing this situation to get the error messages for the screen, I broke down the trigger. After this the trigger did not work anymore. I needed to change the Change type to something else, then save and then put back to Create or Added and then it started working again. This means that don’t mix with the change type, choose one and stay there. The http web hook on the background could break or have some error state causing your flow not to work.
Use parallel paths
Since these metadata are not depended on each other, I chose to build parallel paths using two conditions checking if the metadata is set or not. If there is no value, then we don’t do anything.

Then I added getting the role for customer with text, and then need to remember creating the same roles or include Connection Role table content into the solution package. If you don’t use roles, then it is not possible to know which Connection row is which because the From and To fields are polymorphic.

Then format the action to get existing connections which has from value the project and to value the correct role- Remember in Dataverse queries lookups needs column name prefixed with _ and postfixed with _value when you use direct ids. Take the first of the output getting the role assuming there is only one correct with that name.

Then you need a condition to check if the customer (account) value of the project is null or given. With that information you whether to create new connection row or update the existing row(s).

Then you need to check if there was rows with the query getting connections between project and customer (account) table. If not create new row, otherwise update the existing ones.


Delete existing connections if customer is removed
We have not covered case where not required field could be deleted. In this case we need to remove the existing rows. Remember to check in the length expression is greater than 0, when previous section checked that it equals.

Create delete action for Dataverse. When you add the Connection (ConnectionId) from the List Rows action the flow adds the for each there automatically.

Finally you create the another parallel path for project manager. I have not implemented the orphaned rows deletion since the Project Manager field or project is required field and in my case could not be null in any case – not in creation nor update. Remember that project manager points to Users (SystemUser) table.

Remember to change the To-fields pointing correct fields if you copy-paste from Customer actions. And then change the /accounts/ to /systemuers/. I did not – so when testing I was scratching my head why it changed the project manager roles connections to accounts if the connection existed. Creating this blog post made me realize this copy-paste error – so always remember to test what you build.
