cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Samuel_d_Bishop
Regular Visitor

Gallery

How can I stop a gallery collection from duplicating .

I have a gallery using collection. But the gallery duplicate each user . 

 

16345604751303467615882628609754.jpg

1 ACCEPTED SOLUTION

Accepted Solutions


@Samuel_d_Bishop wrote:
Spoiler
Code is .... Patch( leave request, default ( lev rqs), {leave type: gallery.selcted.leave type})

User click Annual and it recreat another choice option again.... Need to stop recreating once picked 
16348297266171527095213797451242.jpg


Yes, any Patch() statement with Defaults() as its second argument will create a new record each time it is executed.

 

There are two ways I see to handle this:

  1. Build some logic into your app that toggles the DisplayMode of that button to DisplayMode.Disabled. This can be as simple as putting a condition into the DisplayMode property using a variable that you toggle after the first time a user submits.
  2. You can build your Patch() into an If() statement that tests if the record already exists, something similar to this:

 

If(IsBlank(
    LookUp('Leave Request', 'Employee Name'.Email = User().Email && 'End Date' = EndDatePicker1.SelectedDate)
    ),
    Patch('Leave Request', Defaults ('Leave Request'), {leave type: gallery.Selected.'leave type'}),
    Notify("Leave Request Already Exists")
)

Using the LookUp(), this code checks first to see if a record exists (you will need to specify criteria that work for your app), and if no record is found then it will execute the Patch().

 

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

7 REPLIES 7
BCLS776
Super User
Super User

It's tough to tell from the picture attachment, but it looks like a collection that has some duplicate records? If those are not desired, check your code for Collect() statements that are being used twice without a Clear() or ClearCollect() to empty the collection.

 

Hope that helps,

Bryan

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.
v-qiaqi-msft
Community Support
Community Support

Hi @Samuel_d_Bishop

Could you please share a bit more about how you collect collection from your gallery?

Do you want to create a collection without duplicates?

 

As @BCLS776 said, maybe you used the Collect() function to collect a record twice. Currently, there is no directly way to solve the duplicated records in the collection. 

 

As an alternative solution, I think you could create a new collection including a new column that concatenates all values that can define the array as unique. Then distinct the records based on the duplicated strings using Distinct().

 

1). I create a collection as below:

 

ClearCollect(originalCollection1,{Country:"CN",Region:"Asia"},{Country:"Japan",Region:"Asia"},{Country:"CN",Region:"Asia"},{Country:"USA",Region:"Ameraica"})

 

2). Create a new collection to add a column to concatenates all values as below:

 

ClearCollect(originalCollection,AddColumns(originalCollection1,"NewColumn",Concatenate(Country,Region)))

 

3). Create a temporary collection with the distinct values from this new column. 

 

ClearCollect(tempCol,Distinct(originalCollection, NewColumn))

 

4). Loop the tempCol and filtering and getting the first values from the originalCollection

 

ForAll(tempCol,Collect(tempCol2,First(Filter(originalCollection , NewColumn=Result))))

 

5). Replace the originalCollection by the second temporary collection.

 

ClearCollect(FinalCol,tempCol2)

 

 

Then you could have a new collection with all duplicated values removed. 

Best Regards,
Qi

I have a choice column from my data source, I made the choices as gallery display for user to pick . The choice picked by the user form another option . 

 

The main goal is to display the choice , while user pick . example, choice option( A, B,  C, ) , User pick A and A creat another option of its self. 

 

How do I stop that 

Spoiler

I have a choice column from my data source, I made the choices as gallery display for user to pick . The choice picked by the user form another option . 

 

The main goal is to display the choice , while user pick . example, choice option( A, B,  C, ) , User pick A and A creat another option of its self. 

 

How do I stop that 


@Samuel_d_Bishop wrote:

I have a choice column from my data source, I made the choices as gallery display for user to pick . The choice picked by the user form another option . 

 

The main goal is to display the choice , while user pick . example, choice option( A, B,  C, ) , User pick A and A creat another option of its self. 

 

How do I stop that 


From the information you've shared so far, I can't tell what's causing duplication of data in your collection. Are you able to share the code related to this choice the user performs? It may be in the OnSelect property of a button or icon.

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

    Spoiler
    Code is .... Patch( leave request, default ( lev rqs), {leave type: gallery.selcted.leave type})

    User click Annual and it recreat another choice option again.... Need to stop recreating once picked 
    16348297266171527095213797451242.jpg


@Samuel_d_Bishop wrote:
Spoiler
Code is .... Patch( leave request, default ( lev rqs), {leave type: gallery.selcted.leave type})

User click Annual and it recreat another choice option again.... Need to stop recreating once picked 
16348297266171527095213797451242.jpg


Yes, any Patch() statement with Defaults() as its second argument will create a new record each time it is executed.

 

There are two ways I see to handle this:

  1. Build some logic into your app that toggles the DisplayMode of that button to DisplayMode.Disabled. This can be as simple as putting a condition into the DisplayMode property using a variable that you toggle after the first time a user submits.
  2. You can build your Patch() into an If() statement that tests if the record already exists, something similar to this:

 

If(IsBlank(
    LookUp('Leave Request', 'Employee Name'.Email = User().Email && 'End Date' = EndDatePicker1.SelectedDate)
    ),
    Patch('Leave Request', Defaults ('Leave Request'), {leave type: gallery.Selected.'leave type'}),
    Notify("Leave Request Already Exists")
)

Using the LookUp(), this code checks first to see if a record exists (you will need to specify criteria that work for your app), and if no record is found then it will execute the Patch().

 

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,331)