cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
simondpalmer
Helper II
Helper II

Collect and ungroup values after a pre-existing row

Using the QuickTask Template (Love it😁) provided I have tweaked a couple of things. I am collecting Planner plans by Teams Group as values but need a pre-existing row to be added to the beginning of the collection. 

Below is what I have:

 

ClearCollect(MyGroupandPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"});
Collect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"groupname",displayName))));
Clear(MyPlansGalleryItems);
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value));

 

Which gathers the information correctly.

Problem is I just want to add the values after the pre-populated collection and not just the values. (Where the red arrow is below).

 

Capture.JPGCapture02.JPG

1 ACCEPTED SOLUTION

Accepted Solutions

An update, you had it correct the issue I had was I had this code for a button AND on app start.. 😯🙃 I hadn't changed the latter yet so it was creating conflicting columns etc.

The code I ended with for the button and on start is below:

Collect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"groupname",displayName))));
Clear(MyPlansGalleryItems);
Collect(MyPlansGalleryItems, {groupname: "Click here", id: "NotAPlan2", title: "to create a new Plan"});
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value));

Thank you for all your help @Eelman 

View solution in original post

7 REPLIES 7
Eelman
Super User
Super User

@simondpalmer 

Try this slight adjustment 

ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value.groupname))

// could also try
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{GroupName: Value.groupname}))

 

Thank you for the reply. Unfortunately those don't work. The first idea created the collection I showed before. The second idea doesn't at all because it is not allowing me to use "groupname" for those values

@simondpalmer 

Sorry, I think I may have misunderstood you initial question. Are you wanting the first line of code to be a record inside the collection MyPlansGalleryItems?

 

If so, it seems like you have the schema setup to simply use a Collect() function ie

Collect(MyPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"});

 

This will add it to the bottom, is that OK? If you are looking to use them as a first record in the list you could start them with underscore and use Sort(). If this record is to be column headings you could use RenameColumns on MyPlansGalleryItems?

 

 

 

Thanks, the "NotaPlan2" appears at the top of a combobox for the user to select when creating a new plan. Hence the need to have it as the first record. I guess i can use Sort function once I have added this custom record to the ungrouped values. Just would be nice to be able to Collect by index or something of that nature.

However, I still cant add the custom record "NotaGroup2". It seems it is not allowing me to use the new column I added "Groupname" to add additional values to it. How so? Below is the code I have:

ClearCollect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"Groupname",displayName))));
Clear(MyPlansGalleryItems);
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{Groupname: Value.groupname}));
Collect(MyPlansGalleryItems, {Groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"})

 

To get it to work I have to rename "Groupname" to another name when I use the ForAll function, shown below:

ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,{Groupname: Value.groupname}));

 

@simondpalmer 

Where you are using AddColumns() I think it is creating then removing that column name because you really are not using it.

 

The schema of the collection MyPlansGalleryItems is:

groupname | id | title

... so you should be using these headings to add a record/s, ie

Collect(MyPlansGalleryItems, {groupname: "NotAGroup2", id: "NotAPlan2", title: "Create New Plan"})

 

I actually think you could remove that AddColumns code and still get the same outcome?

An update, you had it correct the issue I had was I had this code for a button AND on app start.. 😯🙃 I hadn't changed the latter yet so it was creating conflicting columns etc.

The code I ended with for the button and on start is below:

Collect(MyGroupandPlansGalleryItems,If(!IsEmpty(MicrosoftTeams.GetAllTeams().value),ForAll(MicrosoftTeams.GetAllTeams().value, AddColumns(Planner.ListGroupPlans(id).value,"groupname",displayName))));
Clear(MyPlansGalleryItems);
Collect(MyPlansGalleryItems, {groupname: "Click here", id: "NotAPlan2", title: "to create a new Plan"});
ForAll(MyGroupandPlansGalleryItems,Collect(MyPlansGalleryItems,Value));

Thank you for all your help @Eelman 

View solution in original post

@simondpalmer 

Glad to see you got it sorted. It can certainly help sometimes to run stuff by others, just to get your thoughts straight 🙂 

 

Just a note on your final code. You are starting it off with Collect and not ClearCollect. This will APPEND data to your collection for every button click. Not sure if you want that or not? You maybe wanting a ClearCollect() or Clear() to start off your code? Just a thought.

 

All the best 🙂 

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 Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

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