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 III
Super User III

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 III
Super User III

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

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,365)