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 Platform Community / Forums / Power Apps / Patch gallery item the...
Power Apps
Unanswered

Patch gallery item then add to collection

(0) ShareShare
ReportReport
Posted on by 97

Hi

I have a gallery linked to items in a sharepoint list.  Each item in the gallery has a checkbox.  When the checkbox is checked I would like to patch the item on the sharepoint list to have a status of "Made", then add that item to a collection (linked to another gallery for viewing).  Then refresh the SP list data source so the ticked item is not visible. (It is filtered on Status = "Required").  Below is my code for OnCheck however it creates 2 entries in the collection?  One of which I believe is all the fields from the SP list?

 

Patch(
 'Unit Register',
 Req_Items.Selected,
 {Status: "Made"}
);
Collect(
 AddProd,
 Req_Items.Selected,
 {
 Date: I_PDate.SelectedDate,
 Title: Contract,
 Unit: Unit
 }
);
Refresh('Unit Register')

Any help much appreciated

Categories:
I have the same question (0)
  • RezaDorrani Profile Picture
    12,143 on at
    Re: Patch gallery item then add to collection

    Hi @sanderson82 

     

    ForAll(
    RenameColumns(Filter(Req_Items.AllItems, Checkbox1.Value = true), "ID", "ID1"), Patch(datasourcename,
    LookUp(datasource, ID = ID1),
    {Status:"Made"}); Collect(
    AddProd,
    {
    Date: I_PDate.SelectedDate,
    Title: Contract,
    UnitVal: Unit
    }
    ))

     

     

    In bold section - make sure the names of the objects example : Date,Title,UnitVal do not clash with names in the actual gallery data source - Notice I renamed Unit to UnitVal

     

    Regards,

    Reza Dorrani

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

  • v-siky-msft Profile Picture
    on at
    Re: Patch gallery item then add to collection

    Hi @sanderson82 ,

     

    Do you mean that once you check a checkbox, two items would be created to collection?

    That is beacuse that the collect formula you used contains two items: Req_Items.Selected (all fields of SP list you mentioned) and {Date: I_PDate.SelectedDate,Title: Contract,Unit: Unit}.

    If you only want to add a new item, no need to add Req_Items.Selected, you can refer to the following formula:

    Patch(
     'Unit Register',
     Req_Items.Selected,
     {Status: "Made"}
    );
    Collect(
     AddProd,
     {
     Date: I_PDate.SelectedDate,
     Title: Contract,
     Unit: Unit
     }
    );
    Refresh('Unit Register')

    Best regards,

    Sik

  • sanderson82 Profile Picture
    97 on at
    Re: Patch gallery item then add to collection

    Thanks @v-siky-msft 

     

    Is it possible then to reverse this?  i.e if a unit is checked and appears on the gallery of the new collection but the users as made an error, can it be unchecked in the gallery and re-appear on the original list?

  • v-siky-msft Profile Picture
    on at
    Re: Patch gallery item then add to collection

    Hi @sanderson82 ,

     

    Of course, just still use patch function to patch the status to SP list, Use remove function to delete the record of collection.

    Please put following formulas to Onuncheck property of check box.

    Patch(
     'Unit Register',
     Req_Items.Selected,
     {Status: "Required"}
    );
    Remove(AddProd, LookUp(AddProd, Title = thisitem.Contract));
    Refresh('Unit Register')

     Best regards,

    Sik

  • sanderson82 Profile Picture
    97 on at
    Re: Patch gallery item then add to collection

    Hi @v-siky-msft 

     

    Not sure if I have this right.  On the gallery on the left of the screen (Req_Items showing SP list 'Unit Register') I check the box, this sets the status to made and adds it to the gallery on the right of the screen (Made_Items showing collection 'AddProd').  Thanks to your input this is now working.

     

    However, Req_Items is filtered to only show units with status "Required" so once the above is complete and the status is set to "Made" and I do a refresh of 'Unit Register' this record disappears and is only visible on the right hand side in Made_Items.  It is on this record that if it has been added by mistake I would like to remove the item from the gallery/collection and also patch the original record with status "Required" and refresh 'Unit Register' so it re-appears.

     

    Hope this makes sense

     

    Regards

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

Forum hierarchy changes are complete!

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 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 322 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 209 Super User 2025 Season 2

Last 30 days Overall leaderboard