cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
milky_bar_may
Helper IV
Helper IV

Prevent a patch if record already exists

Hi everyone! 

 

I have a Sharepoint list and a PowerApp.

 

On my Sharepoint List I have 2 columns: Director and Movie. An example of a record that has been entered from the App to the List, is Stanley Kubrick and Eyes Wide Shut.

 

Now the next time someone uses the App I want to prevent this duplicate selection from being patched to the list. 

 

Is there anyway that I can code the patch function so it would prevent a duplicate selection like this from being push and return an error message saying "item already exists"? 

 

Many thanks !! 

 

Milky

3 ACCEPTED SOLUTIONS

Accepted Solutions
eka24
Super User
Super User

You can look at the trad below;

https://powerusers.microsoft.com/t5/Building-Power-Apps/Check-if-record-exist/td-p/377121

 

I added the patch bit:

If(CountRows(Filter(DataSource,Name = Textbox.Text)) > 0,"Exist",
Patch({...})

View solution in original post

yashag2255
Dual Super User II
Dual Super User II

Hey @milky_bar_may 

 

You can configure this using the below expression:
 
If(CountRows(LookUp(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text))=0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))
 
Here, I have assumed that the Director value is input in DirectorInput TextBox control and Movie in MovieInput textbox control.
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

v-yutliu-msft
Community Support
Community Support

Hi @milky_bar_may ,

Do you want to prevent updating with duplicated record?

Whether do you want to prevent updating with record that "doesn't have the same value in both Director field and Movie field" or "doesn't have the same value in  Director field or Movie field"?

1)If you do not want record like this to enter in (Stanley Kubrick and Eyes Wide Shut):

If(CountRows(Filter(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text))>0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

2) If you do not want record like this to enter in (Stanley Kubrick ,....) or (....,Eyes Wide Shut):

If(CountRows(Filter(DataSource, Director=DirectorInput.Text || Movie=MovieInput.Text))>0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

 

Except using countrows function, you could also consider IsEmpty to justify.

For example:

If(!IsEmpty(Filter(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text)),Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
eka24
Super User
Super User

You can look at the trad below;

https://powerusers.microsoft.com/t5/Building-Power-Apps/Check-if-record-exist/td-p/377121

 

I added the patch bit:

If(CountRows(Filter(DataSource,Name = Textbox.Text)) > 0,"Exist",
Patch({...})

View solution in original post

yashag2255
Dual Super User II
Dual Super User II

Hey @milky_bar_may 

 

You can configure this using the below expression:
 
If(CountRows(LookUp(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text))=0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))
 
Here, I have assumed that the Director value is input in DirectorInput TextBox control and Movie in MovieInput textbox control.
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

v-yutliu-msft
Community Support
Community Support

Hi @milky_bar_may ,

Do you want to prevent updating with duplicated record?

Whether do you want to prevent updating with record that "doesn't have the same value in both Director field and Movie field" or "doesn't have the same value in  Director field or Movie field"?

1)If you do not want record like this to enter in (Stanley Kubrick and Eyes Wide Shut):

If(CountRows(Filter(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text))>0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

2) If you do not want record like this to enter in (Stanley Kubrick ,....) or (....,Eyes Wide Shut):

If(CountRows(Filter(DataSource, Director=DirectorInput.Text || Movie=MovieInput.Text))>0,Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

 

Except using countrows function, you could also consider IsEmpty to justify.

For example:

If(!IsEmpty(Filter(DataSource, Director=DirectorInput.Text && Movie=MovieInput.Text)),Notify("Record already exists", NotificationType.Error), Patch(DataSource,Defaults(DataSource),{Director: DirectorInput.Text, Movie: MovieInput.Text}))

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @v-yutliu-msft , @yashag2255 , @eka24 

 

Many thanks to you all for the responses. Each worked beautifully. 

 

Sorry for the delay in responding, had an unfortunate stay in a hospital.

 

Many thanks again! 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,273)