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

Updating a record within SharePoint list using Patch function

Hey folks,

 

I'm trying to create and update a record within a SharePoint list using the Patch function.

 

It seems that I can both create and update the record however when updating the record the other fields are wiped. I need to do it in this fashion as the Form contains to fields that perform a lookup in SharePoint. In my experience you cannot have 2 lookup fields on a single form as this creates a "server-side" error.

 

Here is my "code" : 

 

Patch('HIEN Scheduling', Defaults('Scheduling'),
{
    Email : DataCardValue158.Selected,
    MigrationWave : DataCardValue154.Selected,
    Session : DataCardValue157.Selected,
    Location : DataCardValue156.Selected,
    UserApplications : DataCardValue5.Text,
    AppsInSCCM : DataCardValue6.Selected,
    Notes : DataCardValue1.Text
}
);

Patch('Scheduling', 
{Email : DataCardValue158.Selected}, 
{Asset: DataCardValue168.Selected})

Both "Email" and "Asset" are lookup fields within SharePoint. Essentially this uses Patch in the first case to create the record. The second patch filters the list to show the single "Email" (There is validation on the list so it will only ever bring back a single value) then updates the "Asset".

 

I've found that this erases the previous fields and only populates the field mentioned in the second patch. "Asset".

 

Thanks.

J

1 ACCEPTED SOLUTION

Accepted Solutions

If I am reading this correctly it is a syntax issue. Try 

Patch('Scheduling', 
Email = DataCardValue158.Selected, 
{Asset: DataCardValue168.Selected})

I don't have an example in front of me to test but I know if you are checking to see if Email equals DataCardValue158.Selected you would not use a : the colon is for assignment, not evaluation.  

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

View solution in original post

3 REPLIES 3

If I am reading this correctly it is a syntax issue. Try 

Patch('Scheduling', 
Email = DataCardValue158.Selected, 
{Asset: DataCardValue168.Selected})

I don't have an example in front of me to test but I know if you are checking to see if Email equals DataCardValue158.Selected you would not use a : the colon is for assignment, not evaluation.  

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

Hi @Shanescows

 

You're right!

 

I also found a better way of doing it, strangely a form submission acts differently than a patch. Meaning I can submit to "lookup fields" at the same time without the issues with "SubmitForm".

 

Thanks,

J

Happy to see u here Shane. Your powerapps videos are great !!!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,550)