Change group owner using Microsoft Flow
In this article we are going to have a look on how to assign a group as owner of another group using Microsoft flow or power automate.
If you want to create a SharePoint group from flow then have a look on
Create SharePoint group from flow
If you want to see how to add users to a group from Microsoft Flow then have a look on How to add users to SharePoint using MS Flow
For simplicity, suppose we have a target group and we want to change the owner to target group to SharePoint site owner
Setting a group as owner of another group is currently not possible with rest and so we will have to use soap based request. lets say that we know the source group id and target group id.
From user interface you can get group id by navigating to site settings >> Site permissions >> click on any group and in the url you will get the group id as value of query string parameter MembershipGroupId
Alternativelly you can get the group id's in Flow it self. to konw how you can have a look on How to add users to SharePoint using MS Flow
Lets start creating workflow
Create a mannually triggered flow
In order to create a mannually triggered flow, follow below steps.
-
Go to https://flow.microsoft.com
-
Click on My flows in left section
-
Click new top and select Instant - from blank
-
Choose mannually triggred flow and click Create
At this time your flow will be created. now lets create two varriables
Click add new step and search for initialize varriable and add a varriable
Varriable name : targetgroupid
Type : number
Value : target group id
Similarly add a new initialize varriable step as below
Varriable Name : ownergroupid
type : number
Value : group id of owner group
Get Site Id
In order to assign permissions, we will need the Id of the site. and thus we need to query on _api/site endpoint. follow below steps to get site id
-
Add a new step "Send an HTTP request to SharePoint"
-
Enter site address
-
In Method choose GET
-
in Uri enter _api/site
-
Add two headers accept and content-type and value of both will be application/json;odata=verbose
And we are done here. we will need to parse the response to get site Id. run the the flow once and from run history copy the response body of above activity.
Add a new step Parse JSON as enter below values
1. In Body enter body from get site id
2. In schema , click generate from sample and paste the response copied above
Now we will be able to get site Id from this step
Add group owner
To add group owner follow below steps.
-
Add a new step "Send an HTTP request to SharePoint"
-
In the address, Select your site address
-
In method select POST
-
In Uri, enter _vti_bin/client.svc/ProcessQuery
-
Add header content-type and set the value as text/xml
-
In body paste below
-
<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<SetProperty Id="1" ObjectPathId="2" Name="Owner">
<Parameter ObjectPathId="3" />
</SetProperty>
<Method Name="Update" Id="4" ObjectPathId="2" />
</Actions>
<ObjectPaths>
<Identity Id="2" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:siteguid:g:target_group_id" />
<Identity Id="3" Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:siteguid:g:owner_group_id" />
</ObjectPaths>
</Request>
Replace siteguid , target_group_id and owner_group_id
Group id is a number. when you open a group in browser then value of query string parameter MembershipGroupId will be group id.
And you are done. Test the flow by mannually triggering and see the result
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Mukesh Tiwari
Always ready to learn new technologies, A problem solver, exhibit to do attitude. Having around 10+ years of experience of development and management skills. I believe don't just set random goals but right goals suited for you.
Page Views :
Published Date :
Jun 27,2020