
Announcements
Hello to everyone.
I have a lot of lists in a sharepoint site. Can I update their current view (alternating row styles) with an http request call without going into one by one and update them by hand?
Thank you in advance.
Hi @NickFot,
Yes that should be possible with three send an http request to SharePoint actions. The first one is to retrieve the list titles (and exclude things like document libraries, system supporting lists). The second one is to retrieve the default view. The third request is to update the CustomFormatter property with the alternating row styles json.
Below is an example
1. Retrieve the lists with a Send an HTTP request to SharePoint action
a. Use the uri below which only selects lists of basetemplate 100 which are not hidden
_api/web/lists?$filter=BaseTemplate eq 100 and Hidden eq false&$select=title
b. Also using the nometadata headers
2. Apply to each loop action
a. Uses the output of the first action
outputs('Send_an_HTTP_request_to_SharePoint')?['body']['value']
3. Second HTTP request to SharePoint action (within the apply to each)
a. Uses the uri below to retrieve the id of the default list view
_api/web/lists/getbytitle('@{items('Apply_to_each')['Title']}')/views?$filter=DefaultView eq true&$select=Id
4. Third HTTP request to SharePoint action (within the apply to each)
a. Uses the id of the second action in the URI
_api/web/lists/getbytitle('@{items('Apply_to_each')['Title']}')/views('@{outputs('Send_an_HTTP_request_to_SharePoint_-_Get_Default_View')?['body']['value'][0]['id']}')
b. Uses MERGE headers
c. Uses the payload below for the body field
{
"__metadata": { "type": "SP.View" },
"CustomFormatter": "{\"additionalRowClass\":{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[{\"operator\":\"%\",\"operands\":[\"@rowIndex\",2]},0]},\"sp-css-backgroundColor-BgLightGray30\",{\"operator\":\":\",\"operands\":[{\"operator\":\"==\",\"operands\":[{\"operator\":\"%\",\"operands\":[\"@rowIndex\",2]},1]},\"sp-css-backgroundColor-noFill\",\"\"]}]},\"rowClassTemplateId\":\"BgColorAlternateRows\"}"
}