cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wi11iamr
Level: Powered On

Patch a Lookup Column: Works fine for New record, but does nothing when Editing existing record

Hi there,

 

I have a single screen to capture a new Incident or edit an existing Incident. Within my incident screen's form I have 2 lookup dropdowns, Partnership & Store, each from their own Sharepoint List.

Because I have to resolve the Lookups, to save the record I'm using Patch.

When creating a new record, the lookup dropdowns are patched from the Partnership & Store lists and the record is saved correctly.

When editing an existing record, while the new values of all non-Lookup fields are updated correctly, the new Partnership & Store values are not saved.

 

Below is the code that is used both for the New and Edit processes.

(For reference, I don't use the "Defaults" part of the Patch function as I prefer to list each of the columns separately) 

    Patch(
        'Merchandiser Inspection',
    /*    Defaults('Merchandiser Inspection'), */
        {
            Partnership: {
                '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                Id: LookUp(
                    Partnership,
                    Partnership = Dropdown_Partnership.Selected.Value,
                    ID
                ),
                Value: Dropdown_Partnership.Selected.Value
            },
            Store: {
                '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                Id: LookUp(
                    Store_1,
                    Store = Combobox_Store.Selected.Store,
                    ID
                ),
                Value: Combobox_Store.Selected.Store
            },
            'Visit Type': rdVisitType.Selected,
            'Call Cycle': dcCallCycle            
        }
    )
;
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
KroonOfficeSol
Level 10

Re: Patch a Lookup Column: Works fine for New record, but does nothing when Editing existing record

Your problem comes from the wrong interpretation of the Default() part of the Patch().

In patch the second part you use to direct the patch to the right record. Default() is telling the Patch() to create a new record or in SQL terms to insert a record. To update you use LookUp() for one record and Filter() for multiple records.

Hope this helps,

Paul
3 REPLIES 3
Highlighted
KroonOfficeSol
Level 10

Re: Patch a Lookup Column: Works fine for New record, but does nothing when Editing existing record

Your problem comes from the wrong interpretation of the Default() part of the Patch().

In patch the second part you use to direct the patch to the right record. Default() is telling the Patch() to create a new record or in SQL terms to insert a record. To update you use LookUp() for one record and Filter() for multiple records.

Hope this helps,

Paul
wi11iamr
Level: Powered On

Re: Patch a Lookup Column: Works fine for New record, but does nothing when Editing existing record

Aah, so when creating a new record I *must* provide the Defaults() component, but when Editing/Updating an existing record, I replace Defaults() with a Lookup or a Filter, probably on the current record’s ID? (Effectively like a SQL “where” clause). Something like:

LookUp('Merchandiser Inspection’, ID=ThisItem.ID)

or instead a Filter, such as:
First( Filter( ‘Merchandiser Inspection’, Id = ThisItem.ID) )

I’m only able to test the above options on Monday, and will advise, thank you.
KroonOfficeSol
Level 10

Re: Patch a Lookup Column: Works fine for New record, but does nothing when Editing existing record

@wi11iamr

 

Indeed, just like in the sql where clause.

 

btw if you tricker a button within the gallery you could also use only ThisItem. So like:

Patch(YourDataSource
, ThisItem
, {}
)

 

Paul