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 / Power Apps Canvas Pat...
Power Apps
Answered

Power Apps Canvas Patching Text to Sharepoint List (Avoid Duplicate Item)

(1) ShareShare
ReportReport
Posted on by 96
Hi,
 
Wondering for any help/advice.
(I am using Canvas Apps using Patch and not a Form on a screen.)
 
I  have this code to patch Email address and Display Names to a Sharepoint List 
 
 
Sharepoint List : My Line Managers List
 
Column Name 1 : 'Service Line Managers Email'
Column Name 2 : 'Service Line Managers Display Name'
 
On my button OnSelect event i have:
 
Patch('My Line Managers List',Defaults('My Line Managers List'),
{
 'Service Line Managers Email':cmbUserDetailsLServiceLineManager.Selected.Mail,
 'Service Line Managers Display Name':cmbUserDetailsLServiceLineManager.Selected.DisplayName
}
);
 
It works great to add a new item with both columns data added successfully.
But with the same data i get a duplicate item.
 
But i want a way to check if the 'Service Line Managers Email' already exits in the Sharepoint List then i don't want to add the data again. (Basically avoiding duplicates)
I maybe could have an error message if there is already an item in the Sharepoint List, but not essential.
 
Please can someone suggest a solution to add the Check if the data already exists in the Sharepoint List and it it does then do not add the string values.
I did look at using Lookup - but couldn't understand how to implement it. 
 
Ideally the correct code to achieve this to put into the fx code on my Button OnSelect event.
 
Thanks in advance 
Categories:
I have the same question (0)
  • Verified answer
    Vish WR Profile Picture
    3,748 on at

    You’re almost right

    This happens because Patch() with Defaults() always creates a new record.

    To prevent duplicates, you can check if the email already exists using LookUp() before inserting

    If(
        IsBlank(
            LookUp(
                'My Line Managers List',
                'Service Line Managers Email' = cmbUserDetailsLServiceLineManager.Selected.Mail
            )
        ),
        Patch(
            'My Line Managers List',
            Defaults('My Line Managers List'),
            {
                'Service Line Managers Email': cmbUserDetailsLServiceLineManager.Selected.Mail,
                'Service Line Managers Display Name': cmbUserDetailsLServiceLineManager.Selected.DisplayName
            }
        ),
        Notify("This email already exists in the list.", NotificationType.Warning)
    )

    This ensures that a new item is created only if the email doesn’t already exist in the list.

    As a best practice, I would recommend enabling “Enforce unique values” on the Service Line Managers Email column in SharePoint. This prevents duplicates at the data source level as well, even if multiple users submit simultaneously.

    Note : Be aware of case sensitivity.  

    Lower('Service Line Managers Email') = Lower(cmbUserDetailsLServiceLineManager.Selected.Mail)

    Please  Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like 

    Visit my blog My Tech Space    LinkedIn  
     

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

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard