sharepointspfxpnp-js

How to get the publishing state of a given page?


Currently I'm trying to get some information of the publishing state of a given page.

Maybe anybody has an idea for this issue.

Thanks in advance

To get information about the page I use pnpjs to retrieve the pages list item as follows:

const itemOfPageEN = (await sp.web.getList(this._sitePagesUrl).items.getById(idOfPageEN))();
console.log(LOG_SOURCE, "itemOfPageEN", itemOfPageEN);

in idOfPageEN I provide the ID of a translated page, to get the corresponding item back.

In my console.log Output I can not find any attribute, which give me any information about the publishing state of the given page.


Solution

  • The item that is returned in your itemOfPageEN variable should have a property OData__UIVersionString that gives you the Major and the Minor version of the page, i.e. 0.1 or 1.0. If the Major version is 0, then there is no published version of the page. If the Major version is 1 or higher, then there is a published version of the page.

    There are other endpoints available that give additional information about the publishing state of the page, for example the versions endpoint. In REST you would add "versions" to the url of the list item that corresponds to the page, like ..._api/Web/Lists(guid'f8ee0b0f-2dd2-4a6b-ad21-6b1e61334d00')/Items(83)/versions.

    Then you get detailed information about all versions of the page, including the Moderation Status which corresponds to the Publishing state. It is in the OData__x005f_ModerationStatus property of the version with the highest version number. If it is 0, then the version is a published version. The other possible values for the Moderation Status are:

    Value Meaning
    0 Approved
    1 Denied
    2 Pending
    3 Draft
    4 Scheduled

    Hth, Matthias