web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Add all to collection button and increase quantity button

(0) ShareShare
ReportReport
Posted on by

Hello everyone, recently I will ask a lot of questions on the forum but this is because I am just getting to know powerapps, and its syntax is not fully understandable to me.


I have a gallery that contains a list of assortments and an inputText field where we enter the number of items of a given item and add it to the collection. Thanks to the "Gochix" user, the button in the gallery for adding an assortment to the gallery does not duplicate a given item, but adds the number of items if a given item has already been added to it.
In addition to the gallery, I have a button that is used to add to the collection all items for which the InputText field is filled. And now, will you help me to make this button also check if a given item already exists, and if so, it will sum it up, and if it is not there, then it will be added to the collection.


here is the code from "Gochix":

With({
aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
 If(IsBlank(aLookup);
 Patch(Zamowienie; Defaults(Zamowienie);
 {
 Ind: ThisItem.Indeks;
 Grupa: ThisItem.Grupa;
 Nazwa: ThisItem.'Nazwa asortymentu';
 Jednostka: ThisItem.'j.m.';
 Liczba: Value(liczba.Text)
 }
 );
 Patch(Zamowienie; aLookup;
 {
 Ind: ThisItem.Indeks;
 Grupa: ThisItem.Grupa;
 Nazwa: ThisItem.'Nazwa asortymentu';
 Jednostka: ThisItem.'j.m.';
 Liczba: aLookup.Liczba + Value(liczba.Text)
 } 
 )
 )
 )

and here's my code for a button outside of the gallery that adds all items where InputText is filled (InputText field is called "liczba"):

ForAll(Filter(Asortyment_lista.AllItems;Value(liczba.Text)>0);Collect(Zamowienie;{Grupa:Grupa;Nazwa:'Nazwa asortymentu';Liczba:liczba.Text;Jednostka:'j.m.';Ind:Indeks}))

 Now the second problem, which seems simple and probably is for most of them, but I've been struggling with it for a few hours and I've already done some solutions from the forum but either I get an error or the button just doesn't do anything. The point is that next to the InputText field in the gallery where I enter the number of items (before I add it to the collection) I would like two buttons
1. Add +1 to quantity button
2. Subtract -1 from the quantity

 

I would also like to thank everyone for their help and the time they spend. The number of my questions may seem like I'm waiting for ready-made solutions, but I just don't understand the syntax of powerapps, so far I've used VisualBasic in excel macros and it takes me a while to switch to powerapps.

I have the same question (0)
  • Gochix Profile Picture
    1,935 Moderator on at
    Re: Add all to collection button and increase quantity button

    Hi @pablik01 ,

    We could modify a bit the code you got already for inside gallery button.

     

    ForAll(Gallery3.AllItems As aRecord,
    With({
    aLookup: LookUp(Zamowienie, Title3.Text = Nazwa)},
     If(IsBlank(aLookup),
     Patch(Zamowienie, Defaults(Zamowienie),
     {
     Ind: aRecord.Ind,
     Grupa: aRecord.Grupa,
     Nazwa: aRecord.Nazwa,
     Jednostka: aRecord.Jednostka,
     Liczba: aRecord.Liczba
     }
     ),
     Patch(Zamowienie, aLookup,
     {
     Liczba: aRecord.Liczba + Value(liczba.Text)
     } 
     )
     )
     )
    )

     

    Try this and let me know if there is any anomalies.

     

    For your + - quantities issue :

    add default value for your quantity input field as ThisItem.Liczba. 

    Add new + icon inside gallery and use formula

     

    UpdateIf(Zamowienie, Nazwa = Nazwa, {Liczba: ThisItem.Liczba + 1})

     

     The same goes for - icon :

     

    UpdateIf(Zamowienie, Nazwa = Nazwa && Liczba > 0, {Liczba: ThisItem.Liczba - 1})

     

  • pablik01 Profile Picture
    on at
    Re: Add all to collection button and increase quantity button

    Add all button:


    throws an error: The type of this argument "Ind" does not match the expected type of Text. Error type found

     

  • Gochix Profile Picture
    1,935 Moderator on at
    Re: Add all to collection button and increase quantity button

    Had a typo mistake. Try now?

    ForAll(Gallery3.AllItems As aRecord,
    With({
    aLookup: LookUp(Zamowienie, Title3.Text = Nazwa)},
     If(IsBlank(aLookup),
     Patch(Zamowienie, Defaults(Zamowienie),
     {
     Ind: aRecord.Indeks,
     Grupa: aRecord.Grupa,
     Nazwa: aRecord.Nazwa,
     Jednostka: aRecord.Jednostka,
     Liczba: aRecord.Liczba
     }
     ),
     Patch(Zamowienie, aLookup,
     {
     Liczba: aRecord.Liczba + Value(liczba.Text)
     } 
     )
     )
     )
    )
  • pablik01 Profile Picture
    on at
    Re: Add all to collection button and increase quantity button

    I had a few bugs but corrected it, i have one more bug and i don't understand it: Liczba not recognized

     

    ForAll(Asortyment_lista.AllItems As aRecord;
    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(IsBlank(aLookup);
     Patch(Zamowienie; Defaults(Zamowienie);
     {
     Ind: aRecord.Indeks;
     Grupa: aRecord.Grupa;
     Nazwa: aRecord.'Nazwa asortymentu';
     Jednostka: aRecord.'j.m.';
     Liczba: aRecord.liczba
     }
     );
     Patch(Zamowienie; aLookup;
     {
     Liczba: aRecord.Liczba + Value(liczba.Text)
     } 
     )
     )
     )
    )

     

    f the plus and minus buttons, also get an error about not recognizing Liczba. I don't know if in this case you should refer to the Order collection. This button is to increase the number field by one, and this field is in the gallery - at this stage we are not adding anything to the collection yet

     

     

    ForAll(Asortyment_lista.AllItems As aRecord;
    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(IsBlank(aLookup);
     Patch(Zamowienie; Defaults(Zamowienie);
     {
     Ind: aRecord.Indeks;
     Grupa: aRecord.Grupa;
     Nazwa: aRecord.'Nazwa asortymentu';
     Jednostka: aRecord.'j.m.';
     Liczba:aRecord.liczba
     }
     );
     Patch(Zamowienie; aLookup;
     {
     Liczba: aRecord.liczba.Text + Value(liczba.Text)
     } 
     )
     )
     )
    )

    in the code above I have no errors but it does not work as it should, i.e. after clicking it adds items but without quantity: in the first field there is nothing instead of quantity and in the next field there is the text "object"

  • Gochix Profile Picture
    1,935 Moderator on at
    Re: Add all to collection button and increase quantity button

    @pablik01 ,

     

    ForAll(Asortyment_lista.AllItems As aRecord;
    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(IsBlank(aLookup);
     Patch(Zamowienie; Defaults(Zamowienie);
     {
     Ind: aRecord.Indeks;
     Grupa: aRecord.Grupa;
     Nazwa: aRecord.'Nazwa asortymentu';
     Jednostka: aRecord.'j.m.';
     Liczba: liczba.Text
     }
     );
     Patch(Zamowienie; aLookup;
     {
     Liczba: aRecord.Liczba + Value(liczba.Text)
     } 
     )
     )
     )
    )

     

    Because this is the gallery of your collection -  it would be a problem to try and add + and - buttons as there would be no way how to assign this NEW number to the Item.(Row)

    If you could share the Items option from gallery then we could have a look how to work around this. Possibly add a temp column through AddColumns and then later clear it after adding everything to the collection.

  • pablik01 Profile Picture
    on at
    Re: Add all to collection button and increase quantity button

    this code adds to the collection, but on the next press it does not add up, however no i broke something totally, after entering the quantity it adds a few items to me

     

     

    ForAll(Asortyment_lista.AllItems As aRecord;
    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(IsBlank(aLookup);
     Patch(Zamowienie; Defaults(Zamowienie);
     {
     Ind: aRecord.Indeks;
     Grupa: aRecord.Grupa;
     Nazwa: aRecord.'Nazwa asortymentu';
     Jednostka: aRecord.'j.m.';
     Liczba: liczba.Text
     }
     );
     Patch(Zamowienie; aLookup;
     {
     Liczba: aRecord.liczba.Text + Value(liczba.Text)
     } 
     )
     )
     )
    )

     

    Items option in gallery

     

    With({asmt:Filter(
     asortyment;StartsWith(
     'Nazwa asortymentu';szukaj_box
     )
     )
     };
     If(
     filtr.Selected.Result = "Pokaż cały asortyment"; asmt;
     Filter(
     asmt;Grupa=filtr.Selected.Result
     )
     )
    )

     

  • pablik01 Profile Picture
    on at
    Re: Add all to collection button and increase quantity button

    I did something like that but the effect is strange

     

     

    ForAll(Asortyment_lista.AllItems As aRecord;
    With({
    aLookup: LookUp(Zamowienie; nazwa_asortymentu_do_dodania.Text = Nazwa)};
     If(IsBlank(aLookup);
     Patch(Zamowienie; Defaults(Zamowienie);
     {
     Ind: aRecord.Indeks;
     Grupa: aRecord.Grupa;
     Nazwa: aRecord.'Nazwa asortymentu';
     Jednostka: aRecord.'j.m.';
     Liczba: Value(liczba.Text)
     }
     );
     Patch(Zamowienie; aLookup;
     {
     Liczba: aLookup.Liczba + Value(liczba.Text)
     } 
     )
     )
     )
    )

     

    here's what I got

    pablik01_0-1660500713784.png

     

    button clicked a second time:

    pablik01_1-1660500791400.png

     

     

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

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 819 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 308 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 222 Super User 2025 Season 2

Last 30 days Overall leaderboard