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

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

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

7 REPLIES 7
Microsoft
Microsoft

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.

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 

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

 

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.

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


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

Helper III
Helper III

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

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.

 

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (25,755)