June 23, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….etc

PowerApps – Patch a SharePoint Lookup Field

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.

  • Product Categories List: which has a list of the different products’ categories.

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

 

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.

As a big fan of Patch function instead of the SubmitForm, I wanted to be able to set the Product Category 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);