cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SRen
Frequent Visitor

Keeping existing column when adding columns to subcollection

Hey PA Community

I'm reading out a SharePoint List into a Collection. One SharePoint Column is a multiline textfield with IDs separated by a comma.

Splitting them up again when loading in the collection will result in a collection:

ClearCollect(tempCollection; ForAll(TeamsTemplates; {name:Title; teams: ForAll(Split(TeamsId;", "); {id:Result})}));;

 

which will result in this:

SRen_0-1628158822040.png

So far so good.
Now I want to add a column to each of those subcollections with a lookup on another collection to match the IDs to their DisplayNames. First I'm getting the other collection:
ClearCollect(AllTeams; MicrosoftTeams.GetAllTeams().value);;

 

Then I'll add the column for the subcollections:

ClearCollect(Templates ;ForAll(tempCollection;  AddColumns(teams; "displayName"; LookUp(AllTeams; id = teams[@id];displayName))));;

 

But now I loose the name column in the parent collection. I thought it could be done by adding a ShowColumns() infront like this:

ClearCollect(Templates ;ForAll(tempCollection; ShowColumns(tempCollection; "name"; AddColumns(teams; "displayName"; LookUp(AllTeams; id = teams[@id];displayName))));;

 

But this doesn't even compute..
So how can this be done? Thanks in advance for any help 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
jstrugnell
Regular Visitor

I think I've got it working with the following:

 

ClearCollect(Templates, ForAll(tempCollection, {name: name, teams: AddColumns(teams, "teamName", LookUp(AllTeams, id = teams[@id], displayName))} ));

View solution in original post

8 REPLIES 8
jstrugnell
Regular Visitor

What happens if you try this...

 

ClearCollect(Templates ;ForAll(tempCollection;  AddColumns(name; "name"; teams; "displayName"; LookUp(AllTeams; id = teams[@id];displayName))));;

SRen
Frequent Visitor

@jstrugnell 

Nope sadly doesn't work out. The amount of arguments are wrong. But even with the correct source it won't work:
AddColumns(tempCollection; "name"; name; "teams"; AddColumns(teams; "displayName"; LookUp(AllTeams; id = teams[@id];displayName)))));;

Thanks tho for the try 🙂

jstrugnell
Regular Visitor

What about this? 

 

ClearCollect(tempCollection, ForAll('TeamsTemplates', {name:Title, teams: ForAll(Split(TeamsId;", "); {id:Result})}));
ClearCollect(AllTeams, MicrosoftTeams.GetAllTeams().value);
ClearCollect(Templates, ForAll(tempCollection, {name: name, teams: teams, lookupValue: LookUp(AllTeams, id = teams[@id],displayName)} ));

 

Your syntax seems to use a lot of semi-colons where I would use commas so I'm not sure if you're using a different locale/language? I also don't have your data structures so it's hard to replicate.

SRen
Frequent Visitor

No that doesn't compile either because:
lookupValue: LookUp(AllTeams, id = teams[@id],displayName)} ));
you can't compare a single item with a collection is the exception given. Because we now only iterate over the tempCollection and nolonger over each team we are one level to high up for this comparision.

Regarding the syntax. If think there is a difference between the EU and US platform?
But it's no that wild of a change:
Comma (,) turns to Semicolon (;) and
Semicolon (;) turns into Double Semicolon (;;)

Don't ask me why though 😅

SRen
Frequent Visitor

ahhhhhwww.. I managed to put something together that kinda works.. but now the columns are collections themselves..


Code:
ClearCollect(Templates;
ForAll(tempCollection; {name: name; teams: {id: ForAll(teams; id); displayName: ForAll(teams; LookUp(AllTeams;id = teams[@id];displayName))}})
);;

Result:

suffering.pngSoo frustrating 😞

jstrugnell
Regular Visitor

I think I've got it working with the following:

 

ClearCollect(Templates, ForAll(tempCollection, {name: name, teams: AddColumns(teams, "teamName", LookUp(AllTeams, id = teams[@id], displayName))} ));

View solution in original post

SRen
Frequent Visitor

Yes this works!! 🙂
Thank you so much for ending my suffering and staying so long with me ❤️
This really bothered me.. but I knew there had to be a solution

Glad to help. Power Apps can be a struggle 😊

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,412)