Skip to main content
System administrator Developer Jahia 8.2

How can I tell whether a node has never been published, rather than published and then modified?

Question

How can I tell whether a node has never been published, rather than published and then modified?

Answer

Test for j:lastPublished. A node that has never been published does not have it.

Measured on Jahia 8.2.3.2, following one node through its lifecycle in the EDIT workspace:

Statej:publishedj:lastPublishedj:lastPublishedBy
Never publishedabsentabsentabsent
After publishingtruesetset
After a later edittruesetset
boolean neverPublished = !node.hasProperty("j:lastPublished");

These properties do not tell you "modified"

Look at the last two rows. Editing the node after publication changes none of them - j:published stays true and the timestamps keep their old values.

So this answers "has it ever been published?" and nothing more. If you need "published but changed since", these properties cannot give it to you, and code that tests j:published == true to mean "live and current" is wrong: it means "was published at some point".

For the modified case, compare the EDIT node against LIVE - a node absent from the LIVE workspace has never been published, and a node present in both with differing content has unpublished changes. Jahia's publication service exposes the status used by the UI badges; prefer it over re-deriving the comparison yourself.

Why j:published is misleading on its own

It is publication bookkeeping, set when a publication happens. It is not a live flag, and it does not come off when the content changes. The authoritative statement about what is live is the LIVE workspace itself - a node exists there or it does not.

That is also the cheapest check if you have a session: the node resolving in LIVE means it is published, independently of any property.

In a rule

A PublishedNodeFact tells you a publication just happened, not what the prior state was. To act only the first time a node is published, test j:lastPublished before the publication writes it, or keep your own marker property - the publication properties are not a history.


This article was drafted with AI assistance, then reviewed and curated by Jahia Customer Support engineers before publication.