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 / Prevent a patch if rec...
Power Apps
Answered

Prevent a patch if record already exists

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

 

I've read this thread before i post https://powerusers.microsoft.com/t5/Building-Power-Apps/Prevent-a-patch-if-record-already-exists/m-p/448171#M133242

 

I have a Sharepoint list with a colum Name "Nom et prénom"

 
 
 

Annotation 2020-07-08 160813.png

 
 

Annotation 2020-07-08 161022.png

 

On my apps i add this

 

And finally on the sumit icon, i add this syntax

 

Annotation 2020-07-08 161615.png

 

I don't why i have this warning. 

Is because my column "Nom et prénom" is a person column ?

Thanks for your help

 

 

Categories:
  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    The warning is there because CountRows is not a delegable function.  But if you are sure that the filter will return less than 500 rows, which in this case you are, then you can ignore the warning.

  • eka24 Profile Picture
    20,925 on at

    Revise the portion:

    'Nom et prénom'.Value=nonPernom.Text

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Pstork1 Thank you but since i add the if condition, i can't submit my forms.

     

    @eka24  

    I modify to this ..but nothings change 😞

     

    If(CountRows(Filter('Test QCM';'Nom et Prénom'.DisplayName=NomPrenom.text))>0;
    Notify("Enregistrement existant";NotificationType.Error);;
    
    Patch(
    'Test QCM'; 
    Defaults('Test QCM');
    EditForm1.Updates;
    EditForm2.Updates
    );;
    Navigate(Success;ScreenTransition.Fade)

     

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    If the NomPrenom is a Textinputbox to input Name, the Text property should begin with a capital letter.

    Please modify NomPrenom.text to NomPrenom.Text.

    Hope this helps.

    Sik

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi,

     

    No it's not a inputtext box it's a person or group. 

     

    ALP1_0-1594299464366.png

    But i' ve found a tricky way, i check this on my sharepoint list 

     

    ALP1_1-1594299570745.png

    But this is not a sustainable solution because if the user wants to change his answer late then he can not do so.

     

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    hi @v-siky-msft , @eka24 , @Pstork1 

     

    Let me come back to you and make my need a little more clear.

    When a user edits and changes their saved data, it will create a new record in the SharePoint list.

    How can I avoid this?

     

    In this example, the test user has just changed their information to update it.

    Instead of changing its initial record, this created a second record

     

    ALP1_0-1594334163686.png

     

  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    If you are using a form in Power Apps why are you using Patch() instead of SubmitForm()? 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    In fact, I have a form that is on 2 pages in the app and I need to use patch in order to be able to record the information contained in screen 1 and screen 2. The syntax works very well 

     

     

     

     

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    I didn't test the exact syntax, but you want something similar to this.

    if(isBlank(Lookup(datasource,Title=TitleDatacard.Text)),Patch(datasource,defaults(datasource),Form.updates,Patch(datasource,Lookup(datasource,Title=TitleDatacard.Text,Form.updates)

    The IF checks to see if a Record with the same Title already exists.  The title field is normally an index, but use any field that will be unique for a give record. If the Title doesn't exist (IsBlank) then patch the datasource using the defaults.  That will create a new record.  Otherwise Patch the datasource using a Lookup to update the existing record.

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    That is because that you use Patch with the Defaults function, which is intended to create records. Reference: Patch function 

     

    If you want to make modification, the Base Record should be the Record you try to modify, which should be the Items property of Form.

    For Example, if the EditForm Items property is Gallery1.Selected, then Patch formula should be like this:

    Patch(
    'Test QCM'; 
    Gallery1.Selected;
    EditForm1.Updates;
    EditForm2.Updates
    )

    Just try to replace the Defaults('Test QCM') by the code in Items property of Form.

    Hope this helps.
    Sik

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 258

#3
Mohsin Ali Profile Picture

Mohsin Ali 231

Last 30 days Overall leaderboard