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({...})

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!
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.

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
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.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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
Users online (1,084)