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 / can't clear a collection
Power Apps
Answered

can't clear a collection

(0) ShareShare
ReportReport
Posted on by 820

Hi

I have a collection that is triggered when something is changed in a gallery controls

Then i have a button where i add new lines and upon adding a line i check if there is something in collection and if yes i patch the recor5ds with the value in collection and then i clear that collection and create new record but with that when io create new record all existing records in that gallery are added to collection again. I can't figure out what cause it to act like that. please help me figure it out, This is my code:

//---Check if something exists in collection
If(
CountRows(colTaskUpdatesDarbai)>0,
Patch(
Remontai,

ForAll(

colTaskUpdatesDarbai,


Patch(
LookUp(Remontai,new_RemontaiId=ThisRecord.Remontai),
{

//---Update records in Table with collection values

//new_irasotipas:"0",
// new_uzsakymonumeris: LookUp(Uzsakymai,'Užsakymo numeris'=ComboBoxUzsakymoNumeris.Selected.Result),
new_uzsakymonumeris: LookUp(Uzsakymai,'Užsakymo numeris'=ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris'),
//new_data: new_data,
//new_valstybinisnumeris:LookUp(Automobiliai,'Valstybinis numeris'=new_valstybinisnumeris),
//new_automobiliorida:Value(new_automobiliorida),
new_darbukategorija: LookUp('Darbų kategorijos',new_darbukategorija=cnew_darbukategorija),
new_darbas: LookUp(Darbais,'Darbo pavadinimas'=new_darbas),
new_darbuotojas:LookUp(Darbuotojai,'Darbuotojo kodas'=cnew_darbuotojas),
new_kiekis: Value(new_kiekis),
new_kaina:Value(new_kaina),
new_suma:Value(new_suma)

}
)
)
);
Clear(colTaskUpdatesDarbai);

//----After update create new record

Patch(
Remontai,
Defaults(Remontai),
{
new_uzsakymonumeris:LookUp(Uzsakymai,'Užsakymo numeris'=ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris')
//new_valstybinisnumeris:LookUp(Automobiliai,'Valstybinis numeris'=ComboBoxValstybinisNumeris.Selected.'Valstybinis numeris')
}
),
Clear(colTaskUpdatesDarbai);

//----If nothing exists in collection create new record

Patch(
Remontai,
Defaults(Remontai),
{
new_uzsakymonumeris:LookUp(Uzsakymai,'Užsakymo numeris'=ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris')
//new_valstybinisnumeris:LookUp(Automobiliai,'Valstybinis numeris'=ComboBoxValstybinisNumeris.Selected.'Valstybinis numeris')
}

)
);
Clear(colTaskUpdatesDarbai);

 

Even after last Clear the collection still exists

Categories:
  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

    Hi,

     

    Where is colTaskUpdatesDarbai being collected and what is the formula you have there?

  • julijazas Profile Picture
    820 on at

    @jcfDaniel 

    colTaskUpdatesDarbai is collected on a buttonClick and my controls in gallery property on change is set to Select(buttonClilck) so whenever change happens button is clicked and changes are recorded to gallery

     

    This is the code for collection:

    If(ThisItem.Remontai in colTaskUpdatesDarbai.new_RemontaiId,
    Update(colTaskUpdatesDarbai,
    LookUp(colTaskUpdatesDarbai,new_RemontaiId=ThisItem.Remontai),
    {
    new_RemontaiId: ThisItem.Remontai,
    //new_irasotipas:"0",
    cnew_uzsakymonumeris: ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris',
    //new_data: DatePicker1.SelectedDate,
    //new_valstybinisnumeris: ComboBoxValstybinisNumeris.Selected.'Valstybinis numeris',
    //new_automobiliorida: txtRida.Value,
    cnew_darbukategorija: ComboBoxDarbuGrupe.Selected.'Darbų kategorija',
    new_darbas: ComboBoxDarbai.Selected.'Darbo pavadinimas',
    cnew_darbuotojas: ComboBoxDarbuotojas.Selected.'Darbuotojo kodas',
    //new_kiekis: Value(txtKiekis.Value),
    new_kiekis:txtKiekis.Value,
    new_kaina: txtKaina.Value,
    new_suma: txtKiekis.Value*txtKaina.Value
    }),


    Collect(
    colTaskUpdatesDarbai,
    {
    new_RemontaiId: ThisItem.Remontai,
    //new_irasotipas:"0",
    cnew_uzsakymonumeris: ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris',
    //new_data: DatePicker1.SelectedDate,
    //new_valstybinisnumeris: ComboBoxValstybinisNumeris.Selected.'Valstybinis numeris',
    //new_automobiliorida: txtRida.Value,
    cnew_darbukategorija: ComboBoxDarbuGrupe.Selected.'Darbų kategorija',
    new_darbas: ComboBoxDarbai.Selected.'Darbo pavadinimas',
    cnew_darbuotojas: ComboBoxDarbuotojas.Selected.'Darbuotojo kodas',
    new_kiekis:txtKiekis.Value,
    new_kaina: txtKaina.Value,
    new_suma: txtSuma.Value

    }
    )
    )

     

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

    And that gallery you are monitoring for change, what's in its Items?

  • julijazas Profile Picture
    820 on at

    @jcfDaniel 

    Filter(Remontai,'Užsakymo numeris'.'Užsakymo numeris'=ComboBoxUzsakymoNumeris.Selected.'Užsakymo numeris')

  • Verified answer
    jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

    You have a gallery with records from Remontai. When this gallery changes you collect to another collection and then patch back to Remontai... I believe you are in a loop.

  • julijazas Profile Picture
    820 on at

    @jcfDaniel 

    You think when i add new record gallery refreshes and causes all controls to execute On Change action?

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

    @jja , yes

  • julijazas Profile Picture
    820 on at

    @jcfDaniel 

    I just found a strange workaround i did in other project on this case.

    I concatenate ThisItem gallery values and concatenate Input vales and on change action i check if these 2 are equal then false else i click the button.

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

    That's nice. So the conclusion that that a loop was in play was correct, yes?

  • julijazas Profile Picture
    820 on at

    @jcfDaniel 

    Yes loop was in that play it refreshes gallery and causes onchange property to activate.

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard