web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to prevent duplica...
Power Apps
Unanswered

How to prevent duplicated items upon OnSelect Patch Collection Data to Sharepoint list

(0) ShareShare
ReportReport
Posted on by 95

Hi all,

I have a button containing the code as shown below. Whenever a user presses on the submit button, the relevant datafieldvalues will be patched to the respective sharepoint list columns. However, duplicated entries are created whenever the button is pressed. I am aware that Microsoft Flow can lookup at sharepoint list to set conditions and prevent duplicated entires. However, would it be possible to prevent duplicated entries in the first place through PowerApps?

Alois_0-1605159782039.png


Regards,
Alois

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    on at

    Hi @Alois ,

     

    Could you please share more details about your scenario? Do you want to prevent user from multi-times clicking the submit button?

     

    If you do, you could add if statement into you patch function like below:

    ForAll(
     Scheduleditems,
     If(
     IsEmpty(
     LookUp(
     ‘Scheduled Items’,Title= Title7_4.Text && ‘Swab Test Time’ = Subtitle5_33.Text, ID
     )
     ),
     Patch(
     ‘Scheduled Items’,
     {
     Title: Title7_4.Text,
     ‘Swab Test Time’: Subtitle5_33.Text,
     ……
     }
     )
     )
    )

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Alois Profile Picture
    95 on at

    Hi @v-jefferni ,

    I'm trying to prevent duplicated patched entries regardless how the number of times the button is pressed. 

    I attempted to use your formula but the results are the same - duplicated entries were created.

    Regards,
    Alois 

  • v-jefferni Profile Picture
    on at

    Hi @Alois ï¼Œ

     

    Duplicate entries in SharePoint mostly happen when users click the button continuously while there may be delay in SharePoint creating new records. 

     

    There is a solution in below thread for you to refer to:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Prevent-Duplicate-Inserts-During-a-Patch-in-Button-s-OnSelect/m-p/22773

     

    In short words, create an update context on the submit button to make it disable after once clicking.

     

    Please have a try and hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Alois Profile Picture
    95 on at

    Hi @v-jefferni ,

    I have ascertained the case of duplicated entries is not caused by multiple submissions through the button. For instance, OnSelect the button, 5 existing gallery items will be patched to an empty sharepoint list. Pressing the button again after awhile will append the same set of gallery items to the sharepoint list, creating a total of 10 items then 15 and so on.

    What I'm trying to do here is something suggested by the forum link you shared. The logic should check whether the entry exist in the datasource. If true, do nothing. If false, create row. This will ensure that the sharepoint list will have the latest information without duplicated entries whenever the button is pressed. I am trying to do this without going to MS Flow but I'm getting the syntax wrong. 

    Regards,
    Alois


  • v-jefferni Profile Picture
    on at

    Hi @Alois ,

     

    Have you fixed the syntax wrong in your formula? If not yet maybe you could share the details about the formula so that we could afford any help for you.

     

    Best regards,

    Community Support Team _ Jeffer Ni

  • Alois Profile Picture
    95 on at

    Hi @v-jefferni ,

    Here is the screenshot of the code within the OnSelect function of the button:

    Alois_0-1605574953019.png



    The logic is:
    1. Collect all items with the Scheduled status from the gallery
    2. Check the sharepoint list if there exist collection items with the same ID

    3. If yes, do nothing. If no, patch to sharepoint list
    4. Final product of the sharepoint list will be an updated list without any duplicate

    The current situation is that all Scheduled items will be patched to the sharepoint list upon the press of the button. As a result I get duplicated items in my sharepoint list.

    Regards,
    Alois

  • PaulD1 Profile Picture
    2,914 on at

    I believe the issue is with your test: If(IsEmpty(Filter('Scheduled Items', ID))

    I think you need to compare the ID from 'Scheduled Items' with the ID in your ForAll loop. As it stands, your test is always going to return true if there is at least one item in your 'Scheduled Items' list (If the ID is non-zero it will be treated as 'true').

    The next fun is how to distinguish (disambiguate) between the ID in your ForAll loop and the one you want to test against (ID = ID is always going to return true as well).

    Personally I use rename columns, so you have something like:

    ForAll(RenameColumns('Schedule Items',"ID","ForAllID", LookUp('Schedule Items', ID = ForAllID, true) = false,

    I prefer a LookUp to IsEmpty as I have found that IsEmpty and IsBlank can behave in unexpected ways depending on whether formula level error management is turned on (as PowerApps has some weird ways of dealing with Nulls, and 'not initialised' vs 'initialised but not populated). That may be resolved now, but I just got in the habit of avoiding use of those functions.

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard