Hi Experts,
I have been trying to use the check box to get certain data when the user selects a specific Item and add them to the collection, however, while doing so it adds the records to the collection, but does not remove when a user selects, in fact, it only removes the item from the collection which was last added.
Please find the screenshot below
But the items are unchecked
when I tried to add another 3 items and remove them only one was removed i.e. last entry, rest are not removed, any idea why is this happing?
Final result
The code onCheck :
Set(
varSequence,
CountRows(ExportDataGal.AllItems)
);
Collect(
ExportData,
{
unique_id: varSequence,
data: ThisItem
}
);
The code on UnCheck :
Remove(ExportData,
{
unique_id: varSequence,
data: ThisItem
}
);
Could you please help on this if anyone has any idea what's wrong or missing something.
Thanks a million for taking the time to read and help.
Hi @Anonymous @yashag2255 @zmansuri
Thanks all for the help, support, knowledge, and time. It really means a lot to me, but finally, I got the solution and the result is as below by using a Forall and sequence function.
OnCheck :
If ( ThisItem exactin ExportData, Notify("Item already added", NotificationType.Information, 3000),
Collect(
ExportData, ThisItem
));
OnUncheck
Remove(ExportData, ThisItem)
On Items property of gallery
ForAll(
Sequence(CountRows(ExportData),0),
{
myRecord: Last(FirstN( Sort (ExportData , ID,Ascending ),Value +1)),
rowNumber: Value
}
)
For example, if your Gallery is coming directly from SharePoint then you already have a 'unique_id' you can use ie the ID of the items. So, you can simply just use this is the OnCheck & OnUncheck
// OnCheck
Collect( ExportData, ThisItem)
// OnUncheck
Remove(ExportData, ThisItem );
What is the Items property of your Gallery ie how is it built? Currently, there isn't a relationship between the Gallery and the Collection which is why you cannot manage the deletion of records. We need to create a relationship to be able to do what you are wanting to do.
Hi @yashag2255
Thanks for the reply but seems like it is same solution which was provided by @Anonymous in last reply, sorry to say but it does not work for me as I am using a variable and adding the to collection. could you please help with any other way just in a away where I can create an auto-increment number starting from 0 and end at the last item in the collection. like Sequnece 0, 1, 2, 3, 4, 5. Would be a great help as I can play around then if I get the auto-increment number whe user add the item to the collection and remove vice-versa.
Thanks
Hi @Tapesh
You can use the configuration as below:
OnReset or OnVisible -> Clear(CollectionName)
OnCheck: Collect(CollectionName, {Identifier: ThisItem.ColumnName, data: ThisItem})
OnUncheck: RemoveIf(CollectionName, Identifier= ThisItem.ColumnName)
Here, you have to replace ColumnName with the name of column which stores unique values in the gallery.
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!
Hi @Anonymous
Please see the code below I do not have any other code than this one .
OnCheck
OnUncheck
Sounds like some other code is also firing at the same time, what is the full OnUncheck code and do you have any code in the OnSelect of your gallery? If so, post that as well
Hi , @zmansuri
Yeah, this one works fine for normal but I also have come additional data which I'm adding to the collection while on check and Uncheck but seems like it does not work for Uncheck only.
Any idea why is it so ?
Hi @Anonymous ,
I tried your way but it did not work , I modified it but same the error,
However, I tried this but it's removing all the selections not the just one with the Uncheckmark,
RemoveIf( ExportData, unique_id exactin ExportData.unique_id);
Uncheck:
Remove(CollectionName,ThisItem)
WarrenBelz
146,745
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,091
Most Valuable Professional