cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sn3l
Helper I
Helper I

Patch from Form Submit button to lookup field

Good Morning 

 

I am trying to patch a new record from a "Create New' button on a Form 

 

I am currently using 

 

Patch('Suggested Travel', Defaults('Suggested Travel'), {BookingRef: DataCardValue9})

 

The BookinRef field in my SharePoint list is a lookup column from another table. 

 

When I click submit it creates the record but does no update the BookingRef field in my sharepoint list 

 

Since it is a lookup do I need to add something to my patch. 

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Sn3l ,

 

Thank you for catching that error ! I created a test case and the above formula seems to be working for me, Most probably something else is going wrong. Can you add the following in the on success property

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {BookingRef: {'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Id: DataCardValue9.Selected.Id,
            Value: DataCardValue9.Selected.Value
        }
    }
);
Notify("Data was patched successfully",NotificationType.Success,5000);

Anonymous_Hippo_0-1666625178797.png

 

Now when you submit the form are you seeing the above message ? if yes then it means that your form submit is working correctly. If no then your submit form might have some issues

 

Check your actual data source and see if any data is getting updated ? Also look if the variable lastformsubit has a value in it, all of this should give you clues into why it is not working

View solution in original post

10 REPLIES 10
Anonymous_Hippo
Super User
Super User

Hello @Sn3l ,

 

Can you try this

On the button for Submit/save for the form add this (replace with your form name)

 SubmitForm(FormName);
Set(
    LastSubmitID,
    FormName.LastSubmit.ID
);

 

On your Form's OnSuccess Property add this

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {
        BookingRef: DataCardValue9 //Here i think you need to add DatacardValue9.Text if it is a text field or DatacardValue9.Selected.Value if a combobox
})



 

Please note that Defaults is used to create a new record . Use patch to update an existing record

 

Hope this helps 🙂

Sn3l
Helper I
Helper I

Hi. 

 

Thank you for the response and help 

 

On the Form on Success Property 

 

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {BookingRef:DataCardValue9})

 

If I add .value since this is a combobox

 

I get the following error

 

Sn3l_0-1666149878592.png

GetRef it is refering to is BookingRef   ( I renamed the column in SharePoint but it kept this name in the List

 

Sn3l_2-1666150089586.png

 

 

 

 

Sn3l
Helper I
Helper I

If I remove the .value There is no error, but if I select and submit.  Nothing happens 

 

Hello @Sn3l ,

 

Can you Try 

{BookingRef:DataCardValue9.Selected.Value})

If you are seeing an error then select the combobox and go to its advanced property and look at the DisplayField if the value in that square bracket is not ["Value"] then replace with whatever value that you see. For example in the below case i will replace my formula with

{BookingRef:DataCardValue9.Selected.Country})

Anonymous_Hippo_1-1666157943977.png

 

Cheers !

Hi @Anonymous_Hippo 

 

Thank you so much for the help. 

 

Can confirm that it is indeed a value field.  It does however not trigger anything and still does not like the .value. 

 

I have also tried  

 

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {BookingRef: {Value:DataCardValue9})

With no luck - No event on "OnSelect" 

Hello @Sn3l ,

 

I missed the fact that this is a lookup column . Dummy me !

 

Lookup columns are special columns and have a particular schema. Therefore can you please try this

 

 

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),{
BookingRef: {'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                            Id: DataCardValue9.Selected.Id,
                            Value: DataCardValue9.Selected.Value
                            
                        }}
)

 

 

 

THis should definetly work ! Else please post the error that you are seeing 

Thank you so much for your help. 

 

I get Invalid Argument error. 

 

Screenshot 2022-10-24 095917.png

With the following no error.  But nothing happens

 

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {BookingRef: {'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Id: DataCardValue9.Selected.Id,
            Value: DataCardValue9.Selected.Value
        }
    }
)

Hello @Sn3l ,

 

Thank you for catching that error ! I created a test case and the above formula seems to be working for me, Most probably something else is going wrong. Can you add the following in the on success property

Patch(
    'Suggested Travel',
    LookUp(
        'Suggested Travel',
        ID = LastSubmitID
    ),
    {BookingRef: {'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Id: DataCardValue9.Selected.Id,
            Value: DataCardValue9.Selected.Value
        }
    }
);
Notify("Data was patched successfully",NotificationType.Success,5000);

Anonymous_Hippo_0-1666625178797.png

 

Now when you submit the form are you seeing the above message ? if yes then it means that your form submit is working correctly. If no then your submit form might have some issues

 

Check your actual data source and see if any data is getting updated ? Also look if the variable lastformsubit has a value in it, all of this should give you clues into why it is not working

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,771)