cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sanderson82
Level: Powered On

Patch gallery item then add to collection

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

5 REPLIES 5
Dual Super User
Dual Super User

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
Level 10

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
Level: Powered On

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
Level 10

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
Level: Powered On

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 346 members 5,902 guests
Please welcome our newest community members: