cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shabilass
Helper II
Helper II

Patch new record and update existing record

Hi everyone.

 

I have a SharePoint list to check if a person submit a form on which category (product/competitor product/manager verification).

 

shabilass_0-1597973412168.png

Whenever user submit a form (this form will store the record in another list, not in this list), PowerApps will check whether the form is submitted under which category and update "1" in this list (above picture). I have made dropdown list to determine this category that have 3 choice (product/competitor product/manager verification).

 

I tried used below patch function, but it creates new record instead of update the column inthe existing record (refer to sarah's record in the picture).

 

If(DataCardValue3.Selected.Value = "Competitor",
   Patch('List Name',
         Defaults('List Name'),
             {
                Title: DataCardValue7.Text,
                Month: DataCardValue4.Text,
                Year: DataCardValue12.Text,
                'Competitor Product': "1"

}));

If(DataCardValue3.Selected.Value = "Our products",
   Patch('List Name',
         Defaults('List Name'),
         {     Title: DataCardValue7.Text,
               Month: DataCardValue4.Text,
               Year: DataCardValue12.Text,
              'Product': "1"

}));

 

How can I capture whether user submit new record or already have existing record? I know I cannot used the "defaults" on both patch, but don't know how to start.

 

If new record, it will patch and create new record.

If existing record, it will patch/update the column in existing record.

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User III
Super User III

@shabilass 

My code below will show you how its done.  You can apply a similar concept to your other code segment.

// try to find the record and store it in a variable if it exists
Set(lookupRecord, LookUp(Title: DataCardValue7.Text, Month: DataCardValue4.Text, Year: DataCardValue12.Text,));

If(
    // if no record exists create a new one
    DataCardValue3.Selected.Value = "Competitor" And IsBlank(lookupRecord),
    Patch(
        'List Name',
        Defaults('List Name'),
        {
            Title: DataCardValue7.Text,
            Month: DataCardValue4.Text,
            Year: DataCardValue12.Text,
            'Competitor Product': "1"
        }
    ),

    //if the record exists update instead
    DataCardValue3.Selected.Value = "Competitor" And IsBlank(lookupRecord),
    Patch('List Name', lookupRecord, 'Competitor Product': "1")
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

5 REPLIES 5
mdevaney
Super User III
Super User III

@shabilass 

My code below will show you how its done.  You can apply a similar concept to your other code segment.

// try to find the record and store it in a variable if it exists
Set(lookupRecord, LookUp(Title: DataCardValue7.Text, Month: DataCardValue4.Text, Year: DataCardValue12.Text,));

If(
    // if no record exists create a new one
    DataCardValue3.Selected.Value = "Competitor" And IsBlank(lookupRecord),
    Patch(
        'List Name',
        Defaults('List Name'),
        {
            Title: DataCardValue7.Text,
            Month: DataCardValue4.Text,
            Year: DataCardValue12.Text,
            'Competitor Product': "1"
        }
    ),

    //if the record exists update instead
    DataCardValue3.Selected.Value = "Competitor" And IsBlank(lookupRecord),
    Patch('List Name', lookupRecord, 'Competitor Product': "1")
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Hi @mdevaney 

Thank you for the reply! It works very well!

I'm newbies for PowerApps, please advice.

 

I follow your solution above on my app, I found error when type LookUp(Title:DataCardValue2.Text) same as your. 

 

Here are my questions:

1. why my code below shown error while your sample code did not?  

error2.jpg

2. Refer to above reference, LookUp usually follow with source.  is this exceptional case that no data source required?

 

3. when I insert my data source, I still found error also.

error.jpg

 

please advice, thank you

JacoDeRooij
Helper II
Helper II

@Jira 

I see that's almost two months after your post, but i've experienced the same issue. I resolved it as followed

 

Lookup('DataSource',Title=DataCardValue2.Text)

 

Kind regards

Thanks for your replied even my issue was resolved, i remove my workflow and recreate it.  Then this problem resolved.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,639)