cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
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.

View solution in original post

3 REPLIES 3
Dual Super User
Dual 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
    }
)
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.

View solution in original post

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: 330 members 4,810 guests
Please welcome our newest community members: