cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

Collect, AddColumns, UpdateIf

I'm having some difficulty with the pattern here. Looking for guidance. 

Scenario:

- Collection may originate on-device or from Sharepoint list

- If originating on-device, there is no unique identifier (the auto ID column is applied when the record is Patched to Sharepoint)

- I want to use AddColumns to create the unique ID when originating on-device

AddColumns(
Collect(colActionReport,
    {
        GUID0: varGUID,
        1: Blank(),
        2: Blank(),
        3: Blank()
    }
),"localID", varCounter + 1)

- User then proceeds to populate a colActionReport record using dropdowns/etc.

- OnChange of each dropdown/etc, I'm using UpdateIf to "patch" in records (Can't use Patch here because sometimes colActionReport originates from Sharepoint and I can't Patch a collection originating from Sharepoint, only UpdateIf.

UpdateIf(colActionReport, localID = ThisItem.ID,
    {
        1: test.Selected.Value
    }
)

- Unfortunately, I can't use the AddedColumn "localID". Its not recognized.

 

How do I reference a column added with AddColumns?


Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: Collect, AddColumns, UpdateIf

Hi @ericonline ,

Based on the issue that you mentioned, I think you have some misunderstanding on the AddColumns function.

 

Actually, the result the AddColumns function returned is an temporary table with the transform applied, the underlying table (on your side, it is colActionReport) would not be changed.

 

More details about AddColumns function, please check the following article:

AddColumns function

 

On your side, please consider modify your formula as below:

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: CountRows(colActionReport) + 1 /* <-- Calculate Row Index Value */
}
)

Or

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: Blank() /* <-- Row Index Value */
}
);
Patch(
colActionReport,
Last(colActionReport),
{
localID: varCounter + 1
}
)

 

Then modify the formula within the OnChange property of the Dropdown box to following:

UpdateIf(
colActionReport,
localID = ThisItem.ID, { 1: test.Selected.Value } )

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 REPLIES 3
Super User
Super User

Re: Collect, AddColumns, UpdateIf

Hi @ericonline 

 

AddColumns(
Collect(colActionReport,
    {
        GUID0: varGUID,
        1: Blank(),
        2: Blank(),
        3: Blank()
    }
),"localID", varCounter + 1)

replace with

Collect(colActionReport, { GUID0: varGUID, 1: Blank(), 2: Blank(), 3: Blank() };

ClearCollect(colActionReportNew, AddColumns(colActionReport,"localID",varCounter + 1));

 

This will create a new collection with the added column - also please note the new column value will be same for all the rows

 

 

 

UpdateIf(colActionReport, localID = ThisItem.ID,
    {
        1: test.Selected.Value
    }
)

 update to below (only change is collection name)

 

UpdateIf(colActionReportNew, localID = ThisItem.ID,
{
1: test.Selected.Value
}
)

 

Regards,

Reza Dorrani

 

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

Super User
Super User

Re: Collect, AddColumns, UpdateIf

Thank you for the guidance @RezaDorrani .

I opted to remove the ability to create collections on-device and instead use the Sharepoint-created ID column as the unique identifier. 

There are some UX impacts as user must wait for the server round trip, but overall, a bit easier for me to move forward with. 
Now I can use:

UpdateIf(colActionReport, ID = ThisItem.ID,
    {
        1: Test.Text
    }
)
Highlighted
Community Support Team
Community Support Team

Re: Collect, AddColumns, UpdateIf

Hi @ericonline ,

Based on the issue that you mentioned, I think you have some misunderstanding on the AddColumns function.

 

Actually, the result the AddColumns function returned is an temporary table with the transform applied, the underlying table (on your side, it is colActionReport) would not be changed.

 

More details about AddColumns function, please check the following article:

AddColumns function

 

On your side, please consider modify your formula as below:

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: CountRows(colActionReport) + 1 /* <-- Calculate Row Index Value */
}
)

Or

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: Blank() /* <-- Row Index Value */
}
);
Patch(
colActionReport,
Last(colActionReport),
{
localID: varCounter + 1
}
)

 

Then modify the formula within the OnChange property of the Dropdown box to following:

UpdateIf(
colActionReport,
localID = ThisItem.ID, { 1: test.Selected.Value } )

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Top Community Contributors for September  2019

Top Community Contributors for September 2019 🎉🎉

Let's thank our top community contributors

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

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