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
Resolver II
Resolver II

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? 

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
Resolver II
Resolver II

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? 

View solution in original post

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 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,961)