Share and Enjoy !

Background

For a recent project, I used a Power Automate Flow to update a SharePoint list item when that list item is created or modified. In this use case, I needed to update a multi-valued lookup field. The JSON syntax used to update a multi-valued lookup is not necessarily intuitive, and I always seem to forget the specifics, so I thought I would create this blog post to help “remind me” in the future.

TL;DR

The part I always manage to forget is the JSON format for updating a multi-valued lookup field. Here is the pattern:

  • <InternalFieldName>Id”: { “results”: [<array of values>] }

For example:

  • “MyLookupId”: {“results”: [2,4,6] }

SharePoint Lists

In this example, I have two SharePoint lists. One is a simple list, “Test001”, used for lookup values and the other list, “Entity Information”, references the lookup list data.

  • Test001
    • ID
    • Title
  • Entity Information
    • ID
    • Title
    • Security Group – Single line of text
    • Required Column – Single line of text
    • My Lookup – Lookup
      • Get information from: Test001
      • In this column: Title
      • Allow multiple values: Yes

Power Automate

When an item is created or modified

The Power Automate Flow is triggered “When an item is created or modified” for the “Event Information” list.

Send an HTTP request to SharePoint

In this example, I am setting the values for the “My Lookup” column to the “Test001” list ID values of 2, 4, and 6. Note: In the production code there was another step in the flow that retrieved the list ID values based on a query. To keep this example simple I am using hardcoded values.

Items to note:

  • The “Entity Information” list column has a display name “My Lookup” and an internal name of “MyLookup” (without the space.)
  • The format for the JSON is:
    • <InternalFieldName >Id”: { “results”: [<array of values>] }
    • Don’t forget to append “Id” to the list column name
  • For example:
    • “MyLookupId”: {“results”: [2,4,6] }
Site AddressURL to your SharePoint site
MethodPOST
Uri_api/web/lists/getbytitle(‘Entity Information’)/items(@{triggerOutputs()?[‘body/ID’]})
Headers{
“IF-MATCH”: “*”,
“X-HTTP-Method”: “MERGE”,
“Accept”: “application/json;odata=verbose”,
“Content-Type”: “application/json;odata=verbose”
}
Body{
“__metadata”: {
“type”: “SP.Data.EntityInformationListItem”
},
“SecurityGroup”: “Matthew @{utcNow()}”,
“MyLookupId”: {“results”: [2,4,6] },
“RequiredColumn”: “mc @{utcNow()}”
}

Share and Enjoy !

Related Content: