Welcome back with another post on PowerApps. Today, we will learn about fetching the Microsoft 365 groups created in AD and then it's members. So, let's start
- Open the PowerApps maker portal and create a Canvas App.
- Add-
- Label - lblSearchGroupLabel
- Text Input - txtGroupSearchText
- Button - btnLoadGroups
- DataTable - dtGroups
- DataTable - dtGroupMembers
- Initially, add Label, Text input, button.
- Now, click on "Data" link from left navigation menu and the click on "Add data".
- Here we will add "Office 365 Groups" connection. Search for "office 365".
- Select the "Office 365 Groups" connector.
- Now, on "OnSelect" property of btnLoadGroups, we will add below code to fetch Groups.
ClearCollect( collOffice365Groups, If( Len(Trim(txtGroupSearchText.Text)) = 0, RenameColumns( Office365Groups.ListGroups().value, "displayName", "Group Name", "id", "ID", "mail", "Group EMail ID" ), RenameColumns( Office365Groups.ListGroups( { '$filter': Concatenate( "startsWith(displayName,'", txtGroupSearchText.Text, "')" ) } ).value, "displayName", "Group Name", "id", "ID", "mail", "Group EMail ID" ) ) );
- Run the app and click on button so that the collection get its structure.
- Now, add one DataTable (as mentioned above) named "dtGroups'. Provide the collOffice365Groups as Data Source. Then click on "Edit Fields" link and choose "Group Name", "ID", "Group Mail ID".
- Now, we want to fetch the members of the group, which is selected by user in data table. So, for that, click on "ID_Column1" and choose the "OnSelect" property from the property dropdown.
- Now update the logic as below-
ClearCollect( collOffice365GroupMembers, RenameColumns( Office365Groups.ListGroupMembers(dtGroups.Selected.ID).value, "displayName", "Member Name", "id", "ID", "mail", "EMail", "userPrincipalName", "User Principal Name" ) );
- Now, this code will work only if the user clicks on ID column cell. If the user clicks on "Group Name" or "Group Email ID" column, it will not work.
- For that, select these columns and update the "OnSelect" property as below.
- Now, save the app and play. Load the groups and click on one of the group ID from data table "dtGroups". It will load the data in collOffice365GroupMembers collection.
- Now add another data table "dtGroupMembers".
- Select Data Source as collOffice365GroupMembers. Then click on Edit Fields and then click on Add field. Choose "Member Name", "EMail", "ID", "User Principal Name".
- Save the app and play it. click on Load Groups button then select any group from the dtGroups table.
- The only problem is that when we click on "Load Groups" button, the dtGroups gets loaded but the members of the default selected group doesn't populate in dtGroupMembers table.
- Don't worry, just copy the code written on "ID" column >> OnSelect property of dtGroups table and paste it at the end of OnSelect code of btnLoadGroups.
- Save the app and play it again.
- Now, the only issue you may face is that if the dtGroups is already populated with groups and you make a new search, the dtGroupMembers table doesn't get updated. For this, just clear the collOffice365Groups in the beginning of button click code.
- That's all.
- This is how, you can play with Office 365 groups and their members in PowerApps.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.