Forum Discussion

Untuvakana's avatar
Untuvakana
Copper Contributor
Jun 03, 2021

Creating a flow to change promoted state of a page

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?

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    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.

     

     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:

     

    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:

     

     

    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.

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

     

    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: 

     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.

     

     

    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

    • Magyver201's avatar
      Magyver201
      Copper Contributor
      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?
    • Untuvakana's avatar
      Untuvakana
      Copper Contributor
      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.
      • RobElliott's avatar
        RobElliott
        Silver Contributor
        If you can post screenshots of your flow I'll take a look and see if I can see what's causing that.

Resources