Hello all,
I've been working on a small flow to change permissions on a list in SharePoint for a while.
I used this page as a guide:
https://www.netwoven.com/2020/11/03/set-item-level-permission-in-sharepoint-list-using-power-automate/
The whole thing worked before.
Now I wanted to start the whole thing again from scratch and I get the following error message with the same flow:
The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['d']?['Manager']?['results']' is of type 'Null'. The result must be a valid array.
I have now tried everything from completely recreating, testing each step individually, but I keep getting this error.
Can anyone tell me why this error is occurring and how I can fix it?
As I said, I followed the instructions exactly.
Best regards and thank you very much!
Hi @Expiscornovus ,
Oh my god, of course! The fact that I still have to remove the right first, especially the inheritance, I could have figured that out myself.
I can't thank you enough that this is finally working as it should!
For now there is a subscription to Youtube. 😉
Maybe one more question out of interest.
You said in your first post that my first variant does not work because there is no header.
What does that mean exactly?
Hi @RonGwi,
This could be the whole setup.
Here are the three Uri values. Just copy/paste them into your flow.
Set unique permissions
_api/web/lists/getbytitle('ContactList')/items(@{triggerOutputs()?['body/ID']})/breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)
Retrieve Manager Principal Id
_api/web/lists/getbytitle('ContactList')/items(@{triggerOutputs()?['body/ID']})?$select=Manager/Id&$expand=Manager
Add roleassignment
_api/lists/getByTitle('ContactList')/items(@{triggerOutputs()?['body/ID']})/roleassignments/addroleassignment(principalid=@{outputs('Send_an_HTTP_request_to_SharePoint_-_Get_User_List')?['body']['d']['Manager']['Id']},roledefid=1073741827)
Oh yes I would like to see the screenshot. Thank you!
Hi @RonGwi,
Did the rebuild of your flow include step 2 of the original instructions. The item first needs to have unique permissions before you can add somebody to it. That was step 2 in the original blog you referred to.
Apologies if it was not clear. My suggestion was to keep following that blog but to only remove step 4. And change step 5 (to not use an apply to each but use an expression instead to get the principalid value).
If it helps I can create a screenshot of the whole suggested flow setup?
Hello again,
I am now getting a new error. Sorry, as the question, I am still quite new in the field and do not understand the syntax of the whole yet completely. 🙂
Here again 2 screenshots of the configuration and the error.
I just do not know why the error is displayed in German.
There it says: The operation is not allowed for an object that inherits permissions.
Hi @RonGwi,
I see you are retrieving the whole body in the items() part of your Uri. So, that would explain why the url is too long 🙂
Please add the ['d']['Id'] reference to that expression retrieving the id of the Get User List item.
Hi,
Let me show you how it's set up and what the erroneous output looks like:
Hi @RonGwi,
This Url should be pretty short. The id of the item and the principalid wouldn't be more than 2 or 3 characters honestly.
So, I am surprised you are hitting that maxUrlLength limit.
Before we try to workaround the maxUrlLength limit can you show me what the actually Uri field is in the inputs section of the Send an HTTP request action of the failed flow run history?
Just to double check. You have added the expression via the expression editor? Not as plain text, correct?
Hello Expiscornovus,
thank you very much for your answer. I rebuilt the whole thing and now I get another error:
I've already seen in another post where you talk about a "URL parameter".
How can I include that in an example?
Best regards
EDIT: And yes, in my example I only need one manager and not several. The instructions were only designed so that there can be more than one manager, but I don't need that. 🙂
Hi @RonGwi,
A couple of things about those instructions.
1. First of all the Send an HTTP request to SharePoint - Get User List request would not return a results property in the outputs without Headers. That would explain why you are getting a null value for this field.
2. The manager column would only return one manager, not multiple managers, correct? So, I would say there really is no need to loop through a bunch of items. (Unless that Manager field allows selection of multiple manager for one item 😁)
I would suggest to use an expression Instead of the Parse Json and the apply to each action.
outputs('Send_an_HTTP_request_to_SharePoint_-_Get_User_List')?['body']['d']['Manager']['Id']
In your setup that could look like the below:
_api/lists/getByTitle('ContactList')/items(@{triggerOutputs()?['body/ID']})/roleassignments/addroleassignment(principalid=@{outputs('Send_an_HTTP_request_to_SharePoint_-_Get_User_List')?['body']['d']['Manager']['Id']},roledefid=1073741827)
WarrenBelz
146,618
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,957
Most Valuable Professional