PowerApps Patch Sharepoint lists with Lookup fields throws errors when patching multiple lookupfields - Stack Overflow

admin2025-04-18  3

Problem:

I am trying to use the Patch function in PowerApps to update a SharePoint list named City. The City list contains a lookup column Country referring to the ID, which has additional fields Language and Title marked in its definition. However, I am encountering the following error messages:

Version 1:

"The field 'Country_x003a__x0020_Title' is required."

Version 2:

"Error in 'City': Invalid data was used to update the list item. The field you are trying to update may be read-only."

Lists:

  • Country: Contains fields Title, ID, and Language.
  • City: Contains fields Name, Citizen Count, a lookup for Country, and an additional lookup for Language.

Code:

Here is the code I tried:

Version 1

Patch(
    City;
    Defaults(City);
    {
        Country: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
            'Country_x003a__x0020_Title': CurrentItem.Title; // Correct internal name
            'Country_x003a__x0020_Language': CurrentItem.Language // Correct internal name
        };
    }
)

Version 2

Patch(
    City;
    Defaults(City);
    {
        Country: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
        };

        Country_x003a__x0020_Title: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
        };
    }
)

Details:

  • The Country lookup column requires the Title field to be populated.
  • I have verified that the internal names of the fields in the SharePoint list match those used in the Patch function.
  • The error persists even though I am providing values for Country_x003a__x0020_Title and Country_x003a__x0020_Language.

Question:

How can I resolve this error and successfully patch the Country lookup column with the required fields in PowerApps?

Problem:

I am trying to use the Patch function in PowerApps to update a SharePoint list named City. The City list contains a lookup column Country referring to the ID, which has additional fields Language and Title marked in its definition. However, I am encountering the following error messages:

Version 1:

"The field 'Country_x003a__x0020_Title' is required."

Version 2:

"Error in 'City': Invalid data was used to update the list item. The field you are trying to update may be read-only."

Lists:

  • Country: Contains fields Title, ID, and Language.
  • City: Contains fields Name, Citizen Count, a lookup for Country, and an additional lookup for Language.

Code:

Here is the code I tried:

Version 1

Patch(
    City;
    Defaults(City);
    {
        Country: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
            'Country_x003a__x0020_Title': CurrentItem.Title; // Correct internal name
            'Country_x003a__x0020_Language': CurrentItem.Language // Correct internal name
        };
    }
)

Version 2

Patch(
    City;
    Defaults(City);
    {
        Country: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
        };

        Country_x003a__x0020_Title: {
            '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference";
            Id: CurrentItem.ID;
            Value: CurrentItem.ID;
        };
    }
)

Details:

  • The Country lookup column requires the Title field to be populated.
  • I have verified that the internal names of the fields in the SharePoint list match those used in the Patch function.
  • The error persists even though I am providing values for Country_x003a__x0020_Title and Country_x003a__x0020_Language.

Question:

How can I resolve this error and successfully patch the Country lookup column with the required fields in PowerApps?

Share asked Jan 30 at 11:26 RubickRubick 3094 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If the SharePoint list you are trying to patch a new record into has Lookup columns on which the "Add additional columns from source list" feature has been used (e.g. to show some additional columns from the referenced source list) you may run into an issue where the Patch() function doesn't trigger because it expects those additional columns to somehow be included in the body of the Patch() statement.

If you have that situation, you may get an error like:

Field 'CI: SizeInU' is required.

However, if you actually include the columns which its asking for, it may throw an error, such as:

Invalid data has been used to update the list item. The field you are trying to update may be read only.

It may appear like a catch 22, but to get around the error, you can provide "Blank()" instead of actual values for those read-only fields, and at least in my case, it worked:

Patch(
    CIsInRacks,
    Defaults(CIsInRacks),
    {
        CI: {
            Id: 3,
            Value: 3
        },
        'CI: SizeInU': {
            Id: Blank(), //<------- read-only
            Value: Blank() //<------- read-only
        },
        Rack: {
            Id: 1,
            Value: 1
        },
        RackPositionStart: 41,
        'Rack: RackID': {
            Id: Blank(), //<------- read-only
            Value: Blank() //<------- read-only
        },
        'CI_x003a__x0020_Hostname':{
            Id: Blank(), //<------- read-only
            Value: Blank() //<------- read-only
        }
    }
)
转载请注明原文地址:http://anycun.com/QandA/1744923222a89538.html