0

I'm currently using SharePoint online solution.

I've a list named "Projects" with the column "Title" and a column "People" (it's a people picker with multiple values).

I've already enabled a workflow that creates a new document library each time a new item is added in "Project" list. Also, this workflow breaks permission inheritance using SharePoint web services.

After this step, I would set new permissions (collaboration) to the created document library. I've tried using this HTTP call:

https://contoso.sharepoint.com/test/_api/web/lists/getByTitle('[%Current Item:Title%]')/roleassignments/addroleassignment(principalid=[%Current Item:People%],roleDefId=1073741827)

[%Current Item:People%] is set to return a list of IDs separated with semicolon.

It is currently not working. I guess is not possible to use the list of IDs.

So, should I have to iterate over "People" values in a loop? Then retrieve principal id for each user and then make the call to set permissions?

Is there any example to do this?

1

You are correct, it is not possible to use addroleassignment where principalid is a list of semicolon-delimited User IDs. Both principalid and roledefid are of type Int32. Also, manipulating [%Current Item:People%] to separate the User IDs into independent variables is a great solution. The following Stage will assist you in accomplishing this:

Stage:Set Item-Level Access
    Log Stage: Set Item Level-Access to the workflow history list

/*
  dictRequestHeaders Dictionary Items:
  Accept, String, application/json;odata=verbose
  Content-Type, String, application/json;odata=verbose
  Content-Length, String, 255
*/

  Build {...} Dictionary (Output to Variable: dictRequestHeaders )
  Set Variable: strAccessGroupIDs to Current Item:Access Groups

/*
  Perform a POST API call to break permission inheritance
*/

    App Step
        The actions of this step can read from and write to all items in this site.
            Call [%Workflow Context:Current Site URL%]_api/web/lists/getByTitle('[%Workflow Context:List Name%]')/items([%Current Item:ID%])/BreakRoleInheritance(copyRoleAssignments=true,clearSubscopes=true) HTTP web service with request (ResponseContent to response |ResponseHeaders to responseHeaders |ResponseStatusCode to Variable: strBreakRoleInheritance )

/*
  The following Loop will:
  1 Separate User IDs from a semicolon-delimited string to individual strings
  2 Grant Read access to individual Users IDs
  3 Verify access was granted to each User ID
*/

  Set Variable: boolLoop to Yes
    Loop: Call AddRoleAssignment for Each User ID
        The contents of this loop will run repeatedly while: Variable: boolLoop equals Yes

/*
  Count characters from the beginning of strAccessGroupIDs to the first ";"
*/

            Find ; in Variable: strAccessGroupIDs (Output to Variable: intAccessGroupIDLength )

/*
  The following If will execute when there is one User ID in all User IDs
  The following Else will execute when there are many User IDs in all User IDs
*/

            If Variable: intAccessGroupIDLength is less than 0

/*
  Stop looping
  Set the User ID that will receive access
*/

                Set Variable: boolLoop to No
                Set Variable: strAccessGroupID to Variable: strAccessGroupIDs
            Else

/*
  Copy the first User ID from all User IDs
  Replace the first User ID with a " "
  Remove the space from the beginning of all User IDs
*/

                Copy Variable: intAccessGroupIDLength characters from start of Variable: strAccessGroupIDs (Output to Variable: strAccessGroupID )
                Replace [%Variable: strAccessGroupID%]; with   in Variable: strAccessGroupIDs (Output to Variable: strAccessGroupIDs )
                Trim Variable: strAccessGroupIDs (Output to Variable: strAccessGroupIDs )

/*
  Perform a POST API call to grant Read access to a User ID
*/

            App Step
                The actions of this step can read from and write to all items in this site.
                    Call [%Workflow Context:Current Site URL%]_api/web/lists/getByTitle('[%Workflow Context:List Name%]')/items([%Current Item:ID%])/roleassignments/addroleassignment(principalid=[%Variable: strAccessGroupID%],roleDefId=1073741826) HTTP web service with request (ResponseContent to response |ResponseHeaders to responseHeaders |ResponseStatusCode to Variable: strAddRoleAssignment​ )

/*
  Ensure the API call returned "OK"
*/

            Step: Validate (strAddRoleAssignment​​)
                Log Step: Validate (strAddRoleAssignment​​) to the workflow history list
                If Variable: strAddRoleAssignment​ not equals OK
                    Set Variable: boolLoop to No
                    Set Variable: strError to Step: Validate (strAddRoleAssignment​...
                Log /Step: Validate to the workflow history list
    Log /Stage: Set Item-Level Access to the workflow history list
Transition to stage
    If Variable: strError is empty value
        Go to End of Workflow
    Else
        Go to Error

Let me know if there is anything else you need.

Users, groups, and roles REST API reference. (2015, January 08). Retrieved February 07, 2018, from https://msdn.microsoft.com/en-us/library/office/dn531432.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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