cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lgpower
Helper II
Helper II

Path a collection unexpected behaviour

Hi, 

 

I have a collection which I use as Item property for a Gallery. Within the gallery modifications are supposed to be done to the collection. Eventually this collection is patched to a CDS entity. My problem is that when I patch updates to a specific collection Item, the first item in the collection/gallery is patched along with the same values. Other items are not affected, just the first. The patch statement is on the on select property of a Save button within the gallery (one save button per item/row). 

The collection is gathered as follows from CDS entity Urens: 

 

ClearCollect(weekstaatCol;Filter(Urens;Week = Weeknr && WerknemerNummer = userPRSKODE && Jaar = Jaarnr))
;;
Navigate(UrenschermInvoerder)

 

 

On the next screen, UrenschermInvoerder, I have a Gallery with the following Items property: 

 

SortByColumns(Filter(weekstaatCol;DagTxt = Dagselector.Text);"cr45e_recordnr";Ascending)

 

 

In case the gallery is empty a Create button will be visible. This button is supposed to create a record in the CDS entity and collect the result locally. On select code: 

 

 

If(IsEmpty(Filter(UrenGalerie.AllItems;WerknemerNummer = userPRSKODE));
Collect(weekstaatCol;Patch(Urens;Defaults(Urens);
{ 
    Datum: weekStart+datumvar;
    DagTxt:Text(weekStart+datumvar;ShortDate);
    'Dagnummer ':Weekday(weekStart+datumvar;Monday);
    Begintijd: Blank();
    Urenaantal: Blank();
    Week: Weeknr;
    Jaar: Year(weekStart+datumvar);
    Recordnr:1;
    Werknemer: userNaam;
    WerknemerNummer: userPRSKODE;
    WerknemerLink:PersoneelRecord;
    Contracturen:PersoneelRecord.PRS_UREN;
    Tarief:PersoneelRecord.Tarief;
    Goedkeurstatus:"Opgeslagen";
    UitvoerderPRSKODE:PersoneelRecord.PloegUitvoerderPRSkode;
    'Uren (cr45e_uren)':"nieuw";
    Weekstart:weekStart;
    BonNummer:Blank()
   
}
)))

 



Every Gallery Item has a save button. The On Select property is set as follows: 

 

Patch(weekstaatCol;ThisItem;
{
'Uren (cr45e_uren)':ThisItem.DagTxt&ThisItem.WerkLink.cr45e_root_id&ThisItem.WerknemerNummer&ThisItem.WerksoortLink.cr45e_root_id;
WerkLink:cbWerkLink.Selected;
WerksoortLink:cbWerksoortLink.Selected;
Begintijd:cbBegintijd.Selected.Value;
Eindtijd:cbEindtijd.Selected.Value;
Goedkeurstatus:"Opgeslagen";
Urenaantal:Value(UrenaantalTxt.Text);
BonNummer:RegiebonNR.Text;
WerkIDtxt:cbWerkLink.Selected.ROOT_ID;
WerksoortIDtxt:cbWerksoortLink.Selected.ROOT_ID;
Opmerking:OpmerkingTxt.Text;
Werksoortcategorie: cbWerksoortLink.Selected.JUMcategorie
})

 

 

My intention is to ONLY update the current selected Item. However, no matter how I specify the record in the patch statement (by ID, by setting Set(var,ThisItem), the FIRST record of the gallery/collection always gets patched along as well. As a result the first collection Item always has incorrect information. 

I am really lost. Anyone that could have a look with me ? 

With kind regards, 

 

LG

2 ACCEPTED SOLUTIONS

Accepted Solutions
PowerRanger
Super User
Super User

Hi,

 

I have tried to reproduce your steps. I create a collection as shown below:

 

 

ClearCollect(myMonths,
{Number:1,Month:"January",StartDate:Date(2019,1,1),Favorite: false },
{Number:2,Month:"February",StartDate:Date(2019,2,1),Favorite: false },
{Number:3,Month:"March",StartDate:Date(2019,3,1),Favorite: true },
{Number:4,Month:"April",StartDate:Date(2019,4,1),Favorite: false },
{Number:5,Month:"May",StartDate:Date(2019,5,1),Favorite: false });

 

 

I then added a Gallery and linked it to this collection and show the fields Number and Month. I also added a Button and set the OnSelect Method to:

 

 

Patch(myMonths,ThisItem,{Number:ThisItem.Number + 1})

 

 

As expected only the Item/Row I have clicked the Button for got updated and the Number field got changed. All other items/rows remained unchanged.

Screenshot 2020-10-21 210726.png

Does this match your setup? 




​Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

My bad 

There was a on change property that I had been messing around with on one of the comboboxes that caused the unexpected behaviour.. 

Removed this and everything works as expected. 

Thanks anyway 

View solution in original post

3 REPLIES 3
PowerRanger
Super User
Super User

Hi,

 

I have tried to reproduce your steps. I create a collection as shown below:

 

 

ClearCollect(myMonths,
{Number:1,Month:"January",StartDate:Date(2019,1,1),Favorite: false },
{Number:2,Month:"February",StartDate:Date(2019,2,1),Favorite: false },
{Number:3,Month:"March",StartDate:Date(2019,3,1),Favorite: true },
{Number:4,Month:"April",StartDate:Date(2019,4,1),Favorite: false },
{Number:5,Month:"May",StartDate:Date(2019,5,1),Favorite: false });

 

 

I then added a Gallery and linked it to this collection and show the fields Number and Month. I also added a Button and set the OnSelect Method to:

 

 

Patch(myMonths,ThisItem,{Number:ThisItem.Number + 1})

 

 

As expected only the Item/Row I have clicked the Button for got updated and the Number field got changed. All other items/rows remained unchanged.

Screenshot 2020-10-21 210726.png

Does this match your setup? 




​Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item.

If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @PowerRanger 

 

i guess what is different in my setup is that my initial ClearCollect is a filter statement on a CDS entity. 

 

Only if this returns empty, I manually patch the first record to this CDS entity and Collect the return value. This way I immediately collect the Entity ID in the Collection. 

 

Could this cause any conflict ? E.g in collection names vs entity column names ?

 

Wkr,

 

lg 

My bad 

There was a on change property that I had been messing around with on one of the comboboxes that caused the unexpected behaviour.. 

Removed this and everything works as expected. 

Thanks anyway 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,899)