Forum Discussion

Dhiran Gajjar's avatar
Dhiran Gajjar
Iron Contributor
Jun 06, 2023
Solved

SharePoint News and un-publish

Hi,   We have created a site where we want to publish news articles to the company. I have added a news web part to the front page but the issue is that if we want to un-puiblish an article, it sti...
  • RobElliott's avatar
    Jun 07, 2023

    Dhiran Gajjar you don't un-publish the news story, change the version or delete it, you need to demote it from a PromotedState of 2 (published news story) to 0 (normal page). This will remove it from the news web part. To do this, in your site pages library show the Promoted State column. Then format the column in advanced mode and paste in the following JSON:

     

    {
      "$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 : News (Unpublished)' , if(@currentField == 2 , '2 : 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"
          },
          "attributes": {
            "class": "=if(@currentField == 0 ,'ms-fontColor-themePrimary ms-borderColor-themePrimary ms-bgColor-white' , if(@currentField == 1, 'ms-fontColor-themePrimary ms-borderColor-themePrimary ms-bgColor-themeLighter' , if(@currentField == 2 , 'ms-fontColor-white ms-borderColor-themePrimary ms-bgColor-themePrimary','') ) )"
          }
        },
        {
          "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 0:Page)",
              "style": {
                "padding": "10px 20px 10px 20px",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "ms-bgColor-themeLighter--hover"
              },
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "PromotedState": "0"
                }
              }
            }
          }
        }
      ]
    }

     

     

     

    This solution is from Chris Kent on github at https://github.com/pnp/List-Formatting/tree/master/column-samples/promotedstate-demote-news

     

    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources