web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch if record exists...
Power Apps
Unanswered

Patch if record exists or else create new entry in SharePoint list

(0) ShareShare
ReportReport
Posted on by 559

Hi all,

 

I have a gallery which needs to Patch values to different SharePoint list when data s submitted. One list is working fine for the other list when only the Column "Status" value is "Completed" it needs to patch into the list.  When completed if that value exists it must update or else create new entry in SharePoint. 

My Patch code on Submit is:

ForAll(
    Gallery2_1.AllItems As Deployment,
If(
    !Is Blank(ComboBox3_14.Selected. Value) && ComboBox3_14.Selected. Value = "Completed",
    Patch(
        Deployment List,
        Lookup(
            Deployment_List,
            Account Name = ComboBox2_3.Selected.'Name (Title)' && 'Deployment ID' = Value(IDDeploymentLbl.Text)
        ),
        {
             Use Case Name: TextInput4_1.Text,
            Use Case Type: ComboBox3_Selected. Value,
            'Details': TextInput4_4.Text,
            Start Date: DatePicker1_2.Selected Date,
            End Date: DatePicker1_3.SelectedDate,
            Belt Members (Technical SPoCs): ComboBox3_6.SelectedItems,
            'Primary Beneficiary': ComboBox3_5.Selected.Value,
            'Benefit Impact Category': ComboBox3_7.Selected.Value,
            'Impacted processes': TextInput4_5.Text,
            Status: ComboBox3_14.Selected.Value
        }
    ),
        Patch(
           Deployment_List,
            Defaults(Deployment_List),
            {
                'Project Name': ComboBox3_15.Selected.Value,
                AccountName: ComboBox2_3.Selected.'Name (Title)',
               
Use Case Name: TextInput4_1.Text,
            Use Case Type: ComboBox3_Selected. Value,
            'Details': TextInput4_4.Text,
            Start Date: DatePicker1_2.Selected Date,
            End Date: DatePicker1_3.SelectedDate,
            Belt Members (Technical SPoCs): ComboBox3_6.SelectedItems,
            'Primary Beneficiary': ComboBox3_5.Selected.Value,
            'Benefit Impact Category': ComboBox3_7.Selected.Value,
            'Impacted processes': TextInput4_5.Text,
            Status: ComboBox3_14.Selected.Value,
                'Deployment ID': Last(GenAIDeployment_List).'Deployment ID' + 1
            }
        )
    )
);
 
But it is not creating and updating Properly. If I given For All is us creating Duplicate entries if not for all it is saving to SharePoint. From this gallery 2_1 I have to patch values to different SharePoint list.
Any help/suggestion on this.
Categories:
I have the same question (0)
  • AndrewR1 Profile Picture
    1,572 Moderator on at

    Hi @UthhraI would do this to check if the record exists first: 

     

    If(CountRows(Filter(GenAIDeployment_List,AccountName = ComboBox2_3.Selected.'Name (Title)' && 'Deployment ID' = Value(IDDeploymentLbl.Text))) > 0 ,Do the path to update the record,Do your Patch to create new)

     

    Hope this helps

    Please click Accept as solution if my post helped you solve your issue. ✔️ This will help others find the solution to this problem. It also closes the item. Remember, you can accept more than one post as a solution.

    If the content was useful in other ways, please consider giving it Thumbs Up. 👍

    Thanks
    Andrew

  • Sri Profile Picture
    559 on at

    @AndrewR1 

    I have a condition Only when Status is Completed it has to update the record

  • AndrewR1 Profile Picture
    1,572 Moderator on at

    Thats ok you can just wrap the above in to your if condition:

    If(!Is Blank(ComboBox3_14.Selected. Value) && ComboBox3_14.Selected. Value = "Completed",
     If(CountRows(Filter(GenAIDeployment_List,AccountName = ComboBox2_3.Selected.'Name (Title)' && 
     'Deployment ID' = Value(IDDeploymentLbl.Text))) > 0 ,
     Do the path to update the record,
     Do your Patch to create new)
    )

    Hope this helps

    Please click Accept as solution if my post helped you solve your issue. ✔️ This will help others find the solution to this problem. It also closes the item. Remember, you can accept more than one post as a solution. 

    If the content was useful in other ways, please consider giving it Thumbs Up. 👍

    Thanks
    Andrew

  • Sri Profile Picture
    559 on at

    @AndrewR1 

    It is not creating the record nor updating the existing record. No changes

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    Hi @Uthhra ,

    The fundamental issue I can see is that you have used an As statement to refer to the gallery records and then not used it in the Patch - so you will simply always patch the first record. The below addresses a few other things and I also do not know which controls are in the gallery

    With(
     {
     _Update: 
     !IsBlank(ComboBox3_14.Selected.Value) && 
     ComboBox3_14.Selected.Value = "Completed",
     _LastID: Last(GenAIDeployment_List).'Deployment ID' + 1
     },
     Patch(
     GenAIDeployment_List,
     ForAll(
     Gallery2_1.AllItems As Deployment,
     With(
     {
     _ID:
     LookUp(
     GenAIDeployment_List,
     AccountName = Deployment.ComboBox2_3.Selected.'Name (Title)' && 
     'Deployment ID' = Deployment.Value(IDDeploymentLbl.Text)
     )
     },
     If(
     _Update,
     {ID: _ID}
     ),
     {
     'Project Name': Deployment.ComboBox3_15.Selected.Value,
     AccountName: Deployment.ComboBox2_3.Selected.'Name (Title)',
     'GenAI UseCase Name': Deployment.TextInput4_1.Text,
     'GenAI UseCase Type': Deployment.ComboBox3_4.Selected.Value,
     'Details of Pilot': Deployment.TextInput4_4.Text,
     'Pilot Start Date': Deployment.DatePicker1_2.SelectedDate,
     'Pilot End Date': Deployment.DatePicker1_3.SelectedDate,
     'AI Black Belt Members (Technical SPoCs)': Deployment.ComboBox3_6.SelectedItems,
     'Primary Beneficiary': Deployment.ComboBox3_5.Selected.Value,
     'Benefit Impact Category': Deployment.ComboBox3_7.Selected.Value,
     'Impacted processes': Deployment.TextInput4_5.Text,
     'Pilot Status': Deployment.ComboBox3_14.Selected.Value,
     'Deployment ID': _LastID
     }
     )
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Sri Profile Picture
    559 on at

    @AndrewR1 

    For already existing record it is not updating but creating a duplicate record. If two rows are there whose status value is completed, it is updating/creating only 1 record rather than 2.

    Screenshot (100).png
  • Sri Profile Picture
    559 on at

    @WarrenBelz 

    I am getting an error. Since in Deployment list I have created all the fields as Single line text and with function I am getting this record error.

    Screenshot (99).png
  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    @Uthhra ,

    To save a lot of time here, I will go back to your code and add the relevant value - if any of these controls are not in the Gallery, delete Deployment. from the reference

    ForAll(
     Gallery2_1.AllItems As Deployment,
     If(
     !IsBlank(Deployment.ComboBox3_14.Selected.Value) && Deployment.ComboBox3_14.Selected.Value = "Completed",
     Patch(
     Deployment List,
     Lookup(
     Deployment_List,
     AccountName = Deployment.ComboBox2_3.Selected.'Name (Title)' && 
     'Deployment ID' = Value(Deployment.IDDeploymentLbl.Text)
     ),
     {
     'Use Case Name': Deployment.TextInput4_1.Text,
     'Use Case Type': Deployment.ComboBox3_Selected. Value,
     'Details': Deployment.TextInput4_4.Text,
     'Start Date': Deployment.DatePicker1_2.Selected Date,
     'End Date': Deployment.DatePicker1_3.SelectedDate,
     'Belt Members (Technical SPoCs)': Deployment.ComboBox3_6.SelectedItems,
     'Primary Beneficiary': Deployment.ComboBox3_5.Selected.Value,
     'Benefit Impact Category': Deployment.ComboBox3_7.Selected.Value,
     'Impacted processes': Deployment.TextInput4_5.Text,
     Status: Deployment.ComboBox3_14.Selected.Value
     }
     ),
     Patch(
     Deployment_List,
     Defaults(Deployment_List),
     {
     'Project Name': Deployment.ComboBox3_15.Selected.Value,
     AccountName: Deployment.ComboBox2_3.Selected.'Name (Title)',
     'Use Case Name': Deployment.TextInput4_1.Text,
     'Use Case Type': Deployment.ComboBox3_Selected. Value,
     'Details': Deployment.TextInput4_4.Text,
     'Start Date': Deployment.DatePicker1_2.Selected Date,
     'End Date': Deployment.DatePicker1_3.SelectedDate,
     'Belt Members (Technical SPoCs)': Deployment.ComboBox3_6.SelectedItems,
     'Primary Beneficiary': Deployment.ComboBox3_5.Selected.Value,
     'Benefit Impact Category': Deployment.ComboBox3_7.Selected.Value,
     'Impacted processes': Deployment.TextInput4_5.Text,
     Status: Deployment.ComboBox3_14.Selected.Value,
     'Deployment ID': Last(GenAIDeployment_List).'Deployment ID' + 1
     }
     )
     )
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Sri Profile Picture
    559 on at

    @WarrenBelz 

    Only if I give the second Patch separately it is saving to SharePoint list. If I give with lookup nothing is getting saved to SharePoint

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    @Uthhra ,

    You need to do some debugging of your LookUp logic - if you put a label in the gallery with this

    !IsBlank(ComboBox3_14.Selected.Value) && ComboBox3_14.Selected.Value = "Completed",

    you should see true returned on the matching records and false on the others. The true items will update and the false ones create new records.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard