Power Automate N-to-N multiselect update to SharePoint

Using Power Automate to update a multiselect lookup field can be tricky. In this scenario we are going to describe how to do this using SharePoint as the target and a model driven app as the source.

There is no trigger in Power Platform that can perform this action so we are going to use a webhook in the model driven app and an http response trigger.

You will need a model driven app that can be created as described here and at least a a table with many to many relationship and a SharePoint list.

After creating all the above lets create our Power Automate. Navigate to PowerApps studio . In a scenario like this premium license is required for PowerApps. Assuming all is in place and according to best practices , you should by now have distinct solutions created for your Power Automate.

In the solution lets start by creating a new Power automate by selecting type instant.

Instant is the type that will allow the http request trigger to be used. Name your Power Automate as “Dv-Sh Update NtoN SharePoint” and select “When an HTTP request is received” as the trigger.

On the next screen add another action and save.

This will create your URL. Make sure you have Anyone selected on the “who can trigger the flow”. Tap on the copy button and paste the result on a notepad.

The pasted notepad should look like this:

https://prod-00.uksouth.logic.azure.com:443/workflows/a1849ca023fe4c0b96e8c72fcac9a571/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=T5tahidfdfg2SzzbKoM2vyDm0nE-AlhO6vynased3

This needs to be used on the Dataverse webhook which is described here.
It is also very important to limit the trigger to the unique relationship. To do that we need to identify that relationship. This can be found in the entity relationship table in Dataverse. We just need to identify the name of the many to many relationship to use.

In this occasion “bms_DocumentsLibrary_bms_Divisions_bms_Di”. We can now go in the trigger actions and add:

@equals(triggerbody()?['InputParameters'][1]?['value']?['SchemaName'],'bms_DocumentsLibrary_bms_Divisions_bms_Di')

We are now ready to complete our Power Automate. The idea is that multiple locations form a model driven up will update a SharePoint multiselect lookup column.

We get the Id of the main entity and the related one. We then initialize an array to be appended later on with all the data we need. The expression to parse data from the http request action will look something like

“triggerBody()?[‘InputParameters’][0]?[‘value’]?[‘Id’]”

depending on your schema and further down your response you can get values by

“triggerBody()?[‘InputParameters’][2]?[‘value’][0][‘Id’]” .

We can now get the row form Dataverse that we need data from easily.

It is recommended to use compose due to SharePoint action limitations on parsing Dataverse values. So given that we have the primary key of Dataverse in SharePoint and Vice versa we can actually get all the relative ids in order to update the multiselect field . That also requires to append the array with any existing ones . It will look like :

So things are simple now if the ID we got form the trigger is not there we need to add it. In this way we append the array to be used with the correct ID’s only.

The important bit here is to use select to create pairs in the array so that SharePoint can update them. This is relevant to the field you want to update in this case it is called id so the action above creates:

[{ “id”:”<item>”})

This creates the required schema for SharePoint and successfully updates the list.