SamTech 365

Power Platform, Copilot & SharePoint guides by Samir Daoudi

PowerApps – Patch a SharePoint Lookup Field

How to patch a SharePoint lookup column from Power Apps with the right record syntax, with a worked example using two related lists.
SharePoint Lookup

In today’s article, I will explain how we can easily patch a SharePoint LookUp field.

In our demo, we have two SharePoint Lists:

  • Products List: which contains a list of all the products available in a warehouse.SharePoint Lookup
  • Product Categories List: which has a list of the different products’ categories.

SharePoint Lookup

The Products List has a lookup field which points to the Products Categories List.

SharePoint Lookup

 

I created a quick demo app, which has a gallery of all the products with their title, descriptions, categories, and thumbnail.

Bellow the gallery, we have a simple form to create a new product.

SharePoint Lookup

As a big fan of Patch function instead of the SubmitForm, I wanted to be able to set the Product Category SharePoint Lookup straight from a dropdown control in my PowerApps App.

My Add button’s code is as follow:

Patch(
    Products,
    Defaults(Products),
    {
        Title: txtName.Text,
        Description: txtDescription.Text,
        Thumbnail: txtThumbnail.Text,
        Category: {
            Id: drpCategory.Selected.ID,
            Value: drpCategory.Selected.Title,
            '@data.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedRefered"
        }
    }
);

Refresh(Products);
Notify("Your product has been added successfully !", NotificationType.Success);

 

 

Related guides

Discover more from SamTech 365

Subscribe now to keep reading and get access to the full archive.

Continue reading