cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

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
v-xida-msft
Community Support
Community Support

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
RezaDorrani
Dual Super User II
Dual Super User II

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

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
    }
)
v-xida-msft
Community Support
Community Support

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (68,355)