0

We wanted to have a group created while specifying the group owner upon creation. Is that possible?

The rest call to /_api/currentsite/sitegroups using POST will create a group, but there is an "Owner" field that I'm trying to specify, and the type is an "SP.Principal" but I'm not sure how to do that...

Any ideas?

1 Answer 1

1

I'm using Powershell and CSOM to do this so there has to be a way to do it in REST I would think.

Function Set-GroupOwner{

    Param(
        [Parameter(Mandatory=$true,HelpMessage="The URL of the site collection",Position=0)][ValidateNotNull()]
        [string]$SiteUrl,

        [Parameter(Mandatory=$true,HelpMessage="The group that needs updated",Position=1)][ValidateNotNull()]
        [string]$GroupToUpdate,

        [Parameter(Mandatory=$true,HelpMessage="The desired group owner",Position=2)][ValidateNotNull()]
        [string]$GroupOwner

    )
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)

    $owner = $context.Web.SiteGroups.GetByName($GroupOwner)
    $group = $context.Web.SiteGroups.GetByName($GroupToUpdate)

    $group.Owner = $owner
    $group.Update()
    $context.ExecuteQuery()

    $context.Dispose()
}

I adapted it from https://stackoverflow.com/a/25654742/318776. Hope it helps.

8
  • I know how to do this using Powershell and CSOM, but rest within workflow 2013 has it's limitations so I'd like to found out if it's possible to set the Owner on creation using SharePoint Designer 2013 workflows.
    – Mike
    Aug 3, 2015 at 19:59
  • I think it'd just be passing in the string of the group owner Aug 3, 2015 at 20:31
  • I thought so too, Owner and OwnerId to the Workflow Context -> Initator -> UserID (as Integer) turns up with the error code "A PrimitativeValue node with non-null value was found" and "property 'OwnerId' does not exist.." respectively. Not sure where to turn from here. Any other ideas?
    – Mike
    Aug 3, 2015 at 21:20
  • 1
    Looks like it may be a bug: jrjlee.com/2014/01/custom-workflow-activity-for-setting.html
    – Mike
    Aug 4, 2015 at 17:03
  • 1
    even though it's a bug, this is the correct answer for it.
    – Mike
    May 19, 2017 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.