Search code examples
powerappspowerapps-canvas

How to map collection of objects into collection of strings


I'm quite new to PowerApps and from my developer perspective I'm trying to perform something simple, but I couldn't find any good way of doing it.

I'm trying to obtain a list of strings from a list of objects, where each string will be a value of specific property of those objects.

To be more concrete, I have a method

Office365Groups.ListOwnedGroupsV3().value

Which returns a list of objects of type https://www.carlosag.net/PowerApps/Connectors/Office-365-Groups#_Toc645D9ED0_ListOwnedGroups_Response

Now, based on this list I want to create a list of Group IDs, to get a single property (ID) of each object from the list and form a list out of it. I tried different ways, but my code still doesn't compile.

My most promising attempt was something like this:

ForAll(Office365Groups.ListOwnedGroupsV3().value;
Collect(UserGroups;
    {
        groupId: id              
    }
));

Which in theory should put the list of those IDs into UserGroups variable, but it can't compile. I'm pretty sure it must be something stupid with the syntax, but I can't figure it out. I will be grateful for some advise.

Note: I know that AzureAD.GetMemberGroupsV2() can make exactly what I need, but unfortunately I can't use this connector.


Solution

  • I believe this is something you can achieve with the Concat() and Split() functions.

    This will create a semicolon-separated list of the ids, but the return type is string:

    Concat(Office365Groups.ListOwnedGroupsV3().value,id,";")
    

    However if you wrap this in a Split() function and split by semicolons, you get a nice flat table of id strings. The column will is usually named Value or Result by Power Apps automatically, if I remember correctly.