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 / Automatically uncheck ...
Power Apps
Answered

Automatically uncheck and remove in collection

(0) ShareShare
ReportReport
Posted on by 41

Hello,

 

I am developing an application to update data in an Excel and it is working, but I need help on how to do a step.


The application works as follows:
I have a gallery that simulates a table with some Labels brought from Excel and some TextInput for the user to enter information that will be loaded/updated to Excel. For each "row" in this gallery, there is a Checkbox that, when checked (OnCheck), the information for the current line is loaded into a collection and when not checked (OnUncheck), the line is removed from the collection.

Thus, for each row that the user enters the data, he needs to check the Checkbox so that the information is loaded into the collection. And at the end, there is a Save button outside the gallery, which accesses the collection and updates the fields in Excel.

 

As I said at the beginning, all of this is working, but there is a problem that I saw today.


If the user enters the data in the fields and check the Checkbox, the data will be loaded into the collection, but if he needs to make a correction in the fields, the user would need to press the check again to deselect it (OnUncheck) so that the data can be removed from the collection, perform the changes and press the check again (OnCheck) so that the new information is loaded into the collection.


I don't know if this is the best way, but I thought this way:
So that users do not need to deselect the check to make corrections, I thought of a condition: If any field in the current row is inserted information or modified, I need to remove that line from the collection, and the Checkbox must be deselected, forcing the user to check again Checkbox for any modification that is made so that at the end of the modification, it needs to check again and so the data goes to the collection.

 

In short: If a line is changed, Uncheck the Checkbox and if there is data in the collection, remove it.

I don't know how to create this condition, could someone help me, please?

 

Thanks in advance

Categories:
I have the same question (0)
  • Verified answer
    zaphod88 Profile Picture
    502 on at

    Try to use the OnChange property of your TextInput to collect or remove the item by:

    RemoveIf(Collection, ThisItem.ID = ID);

    Collect(Collection, ThisItem)
    As you can see, you may need to add an ID column to your collection to identify the records if it is not there already.


    If you are using a Save/Submit button, you could also think about collecting the records with it. You need to add a column to your property that is set to true by OnChange (or you stay with your checkboxes to filter changed records by). Afterwards, you can
    ClearCollect(Gallery.AllItems, Filter(BooleanColumn = true))
    and patch the Excel file with ForAll().

  • danilohay Profile Picture
    41 on at

    That worked!!
    I followed the idea of OnChange and it worked, I just needed to replace this in all fields of TextInput (TextInput1, TextInput2, TextInput3, ...):

    RemoveIf(Collection, ThisItem.ID = ID);

    Collect(Collection, ThisItem)

    -----------------------------------------------------------------------

    If(IsBlank(LookUp(colUpdates;ID = ThisItem.ID));
    Collect(colUpdates;{'Marcação 1': TextInput1.Text; ID: ThisItem.ID});
    UpdateIf(colUpdates;ThisItem.ID = ID;{'Marcação 1': TextInput1.Text}))


    That's because I have several TextInput fields and I just need to update the current field, keeping the information from the other fields, and I removed the CheckBox, in this logic I don't need it anymore..

    This code is working, but I can't say if it is the best way, is there a better or easier option?
    My save/send button is already working, it loads the information from the collection to Excel, but I liked the idea of the Boolean in OnChange to monitor a modification, for sure I will need to use it in some project.

     

    Thank you very much, @zaphod88 I put the answer as a solution.

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 463

#2
WarrenBelz Profile Picture

WarrenBelz 364 Most Valuable Professional

#3
11manish Profile Picture

11manish 275

Last 30 days Overall leaderboard