Monday, 12 February 2018

SharePoint Online: Unexpected behavior while trying to demote a news page

In my previous blog post I explained in details how the new communication site differentiate between normal Site page and promoted "News" one. it's all about a newly introduced attribute of the SitePage content type called PromotedState.

It's fairly easy to promote a normal site page using the UI using a simple button , but once you promote the page there is no button to return the page to a normal site page changing its promotedState back to "1".

In this post, I'll walk you through an unexpected behavior when we try to update the value of the PromotedState using CSOM to its original value of "1" to hide the page from the OTB news webpart.

I'm going to use exact code sample I've published before with minimal modifications, you can refer to my previous blog post published almost a year and half ago.

Please note: for the modern experience old fashioned custom actions for the ECB context can not be deployed actually you will get an error message if you try to deploy an EditorControlBlock item based custom action

For simplicity and because I just want to show the unexpected behavior when we manually update the promotedState from "2" to "1", I'll create a new JavaScript function to update the PromotedState and I'll call it demoteNewsItem which sets the Promoted State back to "1"

all other helper functions will remain intact, I'll use them to acquire the token and get both digest and e-tag so I'll be able to update the SharePoint item.

I'm going to call the demote item function from my test.js file which I usually use for debugging purpose, I'm just trying to find a quick and easy way to update the site page "PromotedState" attribute.

If we navigate back to the site we can find that the promote button is enabled however it has no effect on the item once you decided to update PromotedState using the previous mechanism when I inspected the PromoteToNews item action (mentioned in details in the previous blog post) I can still see the result is true which gives you the feeling that the process has been successfully executed!

A much better and user-friendly approach (which we will explore in our next blog post) is to create a new SPFx CommandSet for the site pages library. However having the page stuck on demoted state is still an issue as you can see below:

Related Articles