Creating a flow to change promoted state of a page

Copper Contributor

I want to create a flow using power automate that changes site pages promotion stage from 2 to 0 every month if page doesn't consist certain name. This is so pages doesn't show in news feed after certain time but don't be deleted from sharepoint.

How do I change promotional stage in power autome?

7 Replies

@Untuvakana yes this is possible and the flow is shown below. In my example we are changing the Promoted State from 2 to 0 if the Created date is more than 1 month ago and the promoted State equals 2 and the Name column starts with T5.

 

0-SP-SitePages.png

 In the flow use a recurrence schedule as the trigger and then initialize a string variable which will hold the ID number of the page:

1-Flow.png

 

Next, add a compose action to get the date 1 month ago. As you will be doing a date comparison in the next step make sure you use the yyyy-MM-dd format:

2-Flow.png

 

 

To make the flow more efficient we only want to get the items where the created date was less than or equal to the output of the previous compose, i.e more than 1 month ago, and the Promoted State equals 2. Make sure you put the output of the previous compose inside single quote marks in your filter query. You won't find the Site Pages library in the dropdown, so go to the bottom of the dropdown, select Custom value and type Site Pages into the field.

3-Flow.png

 Next, add an apply to each and select value from the dynamic content box. Then append the ID of the page to the variable

4-Flow.png

 

In this example we are only changing the promoted state for those pages where the name starts with T5, so - still inside the apply to each - add a condition to check this: 

5a-Flow.png

 You can leave the red if no channel empty as nothing needs to be done if the name doesn't start with T5.

 

In the green if yes channel add a Send an HTTP request to SharePoint action and 

select your site, then:

 

Method: POST
Uri: _api/Web/Lists/GetByTitle('Site Pages')/Items(@{variables('varID')})

Headers - accept  - application/json;odata=verbose

Headers - content-type - application/json;odata=verbose

Headers - If Match - *
Headers - X-HTTP-Method - MERGE

Body - { '__metadata':{'type':'SP.Data.SitePagesItem'},'PromotedState':0 }

 

Make sure you use 2 underscores before metadata in the body field.

 

6-Flow.png

 

Finally, outside the if yes/if no channels but still inside the apply to each, add a Set variable control and set the value of your variable from the expression tab to null.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

When I try to run this and condition is true I get this error message:
{
"message": "Request ETag-value ' ' doesn't match with object ETag '\"c11dd47d-90dc-4a84-b222-492ad9feb4af,12\"'.\r\nclientRequestId: e310ef09-909c-42c5-9a3b-cb2298dfa355\r\nserviceRequestId: 2180cf9f-5002-3000-0498-428ab618e0d4",
"status": 412,
"source": https://xxxxxxxx/_api/web/lists/GetByTitle('Site%20Pages')/Items(31),
"errors": [
"-1",
"Microsoft.SharePoint.Client.ClientServiceException"
Error message was in another language so sorry for rough translation.
If you can post screenshots of your flow I'll take a look and see if I can see what's causing that.
Thanks, I was just careless and missed one typing error. Now the script runs fine and no errors but when I go back to Sharepoint every item that script found is still in promoted state 2.

I don't know why it doen't change promotion state but it works in every other part..

Screenshot 2021-06-07 151849.png2.pngScreenshot 2021-06-07 152019.png4.png

@RobElliott 

This was the only way I could update the PromotedState field:

2021-12-23_23-33-37.png

_api/web/lists/GetByTitle('Site Pages')/items(###)/validateUpdateListItem

{
  "formValues": [
    {
      "FieldName": "PromotedState",
      "FieldValue": "2"
    }
  ]
}

Ellis

Rob, this is a great suggestion, but I couldn't get the column to update, the flow says it runs, but I don't see the column updating. Any ideas? Could it be because I only have site admin but not site collection admin privileges?