Forum Discussion

JaWa1478's avatar
JaWa1478
Copper Contributor
Oct 16, 2024

News copy - Date

If I copy news, I get a new publication date, which is fine, but the new article may not appear in the news web part because the first publication date is too long ago. Can I change the first publication date for the copy or set the news web part to sort chronologically by publication date and not by creation date? (But that would also mean that it would be re-sorted with each new publication...that wouldn't be a solution either) Does anyone have any advice? 🙂 Thanks!

  • JaWa1478 it's possible to change the First Published Date with some JSON column formatting. In your Site Pages library make sure you are displaying the Promoted State First Published Date columns in the view. In my examle we will change the First Published Date of the highlighted page, One More:

     

     

    Format the Promoted State column with 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 : Normal Page' , if(@currentField == 1, '1 : Draft News Page' , if(@currentField == 2 , '2 : Published News Page','') ) )",
          "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": "25%",
            "display": "=if(@currentField == 2 || @currentField == 1 , 'none' ,'')"
          },
          "attributes": {
            "iconName": "MoreVertical",
            "class": "ms-fontColor-themePrimary ms-bgColor-themeLighter--hover"
          },
          "customCardProps": {
            "openOnEvent": "click",
            "directionalHint": "rightCenter",
            "isBeakVisible": true,
            "formatter": {
              "elmType": "div",
              "txtContent": "Change to 1: Draft News Page",
              "style": {
                "padding": "10px 20px 10px 20px",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "ms-bgColor-themeLighter--hover"
              },
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "PromotedState": "1"
                }
              }
            }
          }
        },
        {
          "elmType": "div",
          "style": {
            "font-size": "18px",
            "cursor": "pointer",
            "padding": "10px",
            "border-radius": "25%",
            "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": "Change to 0: Normal Page",
              "style": {
                "padding": "10px 20px 10px 20px",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "ms-bgColor-themeLighter--hover"
              },
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "PromotedState": "0"
                }
              }
            }
          }
        }
      ]
    }

     

    That will add a button to each item. Click the 3 dots next to the promoted state and you can change the Promoted State down to 0 (normal page), then to 1: draft news. Then when you re-publish the news it will change the Promoted State to 2 (published news page) and also change the First Published Date.

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

     

  • Rob_Elliott's avatar
    Rob_Elliott
    Bronze Contributor

    JaWa1478 it's possible to change the First Published Date with some JSON column formatting. In your Site Pages library make sure you are displaying the Promoted State First Published Date columns in the view. In my examle we will change the First Published Date of the highlighted page, One More:

     

     

    Format the Promoted State column with 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 : Normal Page' , if(@currentField == 1, '1 : Draft News Page' , if(@currentField == 2 , '2 : Published News Page','') ) )",
          "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": "25%",
            "display": "=if(@currentField == 2 || @currentField == 1 , 'none' ,'')"
          },
          "attributes": {
            "iconName": "MoreVertical",
            "class": "ms-fontColor-themePrimary ms-bgColor-themeLighter--hover"
          },
          "customCardProps": {
            "openOnEvent": "click",
            "directionalHint": "rightCenter",
            "isBeakVisible": true,
            "formatter": {
              "elmType": "div",
              "txtContent": "Change to 1: Draft News Page",
              "style": {
                "padding": "10px 20px 10px 20px",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "ms-bgColor-themeLighter--hover"
              },
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "PromotedState": "1"
                }
              }
            }
          }
        },
        {
          "elmType": "div",
          "style": {
            "font-size": "18px",
            "cursor": "pointer",
            "padding": "10px",
            "border-radius": "25%",
            "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": "Change to 0: Normal Page",
              "style": {
                "padding": "10px 20px 10px 20px",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "ms-bgColor-themeLighter--hover"
              },
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "PromotedState": "0"
                }
              }
            }
          }
        }
      ]
    }

     

    That will add a button to each item. Click the 3 dots next to the promoted state and you can change the Promoted State down to 0 (normal page), then to 1: draft news. Then when you re-publish the news it will change the Promoted State to 2 (published news page) and also change the First Published Date.

     

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

     

Resources