Update Dataverse multiselect lookup fields from SharePoint

In this scenario we have a multiselect lookup fields in SharePoint we are trying to update a multiselect N to N field in Dataverse. This procedure is not identical to updating or deleting N to N from Dataverse to SharePoint. It does not require anything on the Dataverse side except a way to send a finalized array to the field parsed in the right way. This array will be used in a relate or unrelate action respectively.

To start with we will use a SharePoint trigger for modify only and initialize a few variables including arrays.

What we need to check first is if there is already a any data related to that column in Dataverse. Given that we have create a corresponding field in an entity with an N to N relationship to a similar table as the one a SharePoint and there are shared Primary keys on both tables we can use those keys on a list row action and get the relate fields from a list row action pointing to the corresponding out of the box relational table that Dataverse creates for N to N relationships. Those Values can be appended on the the initialized array one by one as shown above. The next section uses those is getting the corresponding primary keys from the actual table so that we can compare existing ids with SharePoint ones.

By having all the required info about the relationships we want to create we can now filter our arrays for what ever is not there and unrelate or vice versa.

The screenshots shows unrelate but according to your scenario you can use it respectively.

To sum up to relate or unrelate tables in Dataverse form SharePoint you will need to keep SharePoint s and Dataverse records unique ids in both sides and query the relational in-between. In this way you can decide whether to relate or unrelated according to the users input .