Forum Discussion
News post got stuck in hub site’s news web part even after removing the site from the hub
https://sympmarc.com/2022/03/22/news-post-stuck-in-hub-sites-news-web-part-even-after-deletion/?utm_sq=h0rmeglclv
- Rob_ElliottFeb 22, 2024Silver Contributor
KCLTW you can change the Promoteds State with JSON. Demoting a news article on the associated site should also remove it from the hub site. The JSON for demoting a news page is:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "style": { "flex-wrap": "wrap", "display": "flex", "flex-direction": "row" }, "children": [ { "elmType": "div", "txtContent": "=if(@currentField == 0 ,'0 : Page' , if(@currentField == 1, '1 : Draft News' , if(@currentField == 2 , '2 : Published News','') ) )", "style": { "box-sizing": "border-box", "padding": "4px 8px 5px 8px", "display": "flex", "border-radius": "16px", "height": "27px", "align-items": "center", "white-space": "nowrap", "overflow": "hidden", "margin": "4px 4px 4px 4px", "border": "1px solid", "background-color": "=if(@currentField == 0 ,'#ffffff' , if(@currentField == 1, '#fffcec' , if(@currentField == 2 , '#dafffe','') ) )" } }, { "elmType": "div", "style": { "font-size": "18px", "cursor": "pointer", "padding": "10px", "border-radius": "50%", "display": "=if(@currentField == 0 , 'none' ,'')" }, "attributes": { "iconName": "MoreVertical", "class": "ms-fontColor-themePrimary ms-bgColor-themeLighter--hover" }, "customCardProps": { "openOnEvent": "click", "directionalHint": "rightCenter", "isBeakVisible": true, "formatter": { "elmType": "div", "txtContent": "Demote (Change to 1: Draft News)", "style": { "padding": "10px 20px 10px 20px", "cursor": "pointer" }, "attributes": { "class": "ms-bgColor-themeLighter--hover" }, "customRowAction": { "action": "setValue", "actionInput": { "PromotedState": "1" } } } } } ] }Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)- KCLTWFeb 23, 2024Copper Contributor
Thank you Rob_Elliott. It was my first time using JSON to change the column format and I thought it was a great learning opportunity. I actually applied the code from https://github.com/pnp/List-Formatting/tree/master/column-samples/promotedstate-demote-news so I would be able to change the promoted state back from 0 to 2.
I forgot to mention one thing - I would like the news posts still show up on the site that left the hub, since the news posts will still be relevant to the audiences with the site. So my goal is - after the site left the hub, news posts from the site should be- 1) removed from the hub; 2) staying with the site that left the hub
I think I don't really understand how SP hub site works. The action that seems to be the neatest and actually work is to manually unpublish the news page but leave the Promoted State as 2. By doing so the news still seemed to show up on the site, but disappear from the hub.
I tried to change the Promoted State to 0 using JSON- News posts disappeared from the site but still got stick in the hub's News web part. I have to also manually republish this page as a SP page and after this the post would disappear from the hub. If I then change the Promoted State back to 2 and leave it unpublished, the News would not show up on the hub. But if I republish it, the News would show back up again on the hub.
Good news is that the News page published after the site left the hub will not show on the hub, so I guess another thing I can try is to manually copy and publish the news page and delete the old one.