Use metadata to increment a content version
Overview
Different events can be used to increment a composite version number.
The workflow uses the following trigger actions
initialize a version value using the set-metadata macro
increment the version value using the increment-metadata macro using different triggers for each element of a composite version number
You will need to refresh the page content to view changes in the metadata value if you use the get-metadata macro on the page to display the metadata value.
These examples only work when the workflow is applied as a space workflow. The space workflow must be active to listen for the pagecreated
event to initialize the metadata value.
If the workflow is applied using a content label filter, the trigger setting the metadata should be set to listen for a different workflow event as the content filter workflow may be applied after the page has been created.
Published version
Confluence versions change on each page update. You can use a metadata value and the increment-metadata macro to keep track of the number of times your document transitions to the final state - effectively using this metadata value as your published version value.
{workflow:name=Increment a Metadata Version}
{description}
A simple approval workflow with use of metadata to identify the published versions. The simple version is incremented on approval of content
{description}
{pageheader}
||Type|| Version||Version Number||
|Page metadata|Publishedversion value|@publishedversion@|
|Confluence metadata|Confluence version value|@version@|
{pageheader}
{state:Review|approved=Approved|taskable=true}
{approval:Review}
{state}
{state:Rejected|submit=Review|taskable=true}
{state}
{state:Approved|final=true|updated=Review|hideselection=true}
{state}
{trigger:pagecreated}
{set-metadata:publishedversion}0{set-metadata}
{trigger}
{trigger:pageapproved|approval=Review}
{increment-metadata:publishedversion}
{trigger}
{workflow}
The workflow is added and enabled as a space workflow in the space tools Document Management dashboard for the space.
On creating a page in the space, the value for the metadata publishedversion is set as”0”.
The metadata publishedversion value is set using the set-metadata macro.
The page has not yet been approved as there has been no transition to the final state - the Approved state in our workflow.
Each page edit updates the Confluence version.
Approving the page in the Review state transitions the workflow on the page to the Approved state.
The workflow trigger listening for this page approval event increments the value of the metadata publishedversion.
Editing the page in the Approved state transitions the workflow on the page back to the Review draft state.
Each subsequent approval of the page and transition to the Approved state increments the publishedversion value.
Composite major-minor version content
{workflow:name=Increment a Metadata Version major minor}
{description}
A simple approval workflow with use of increment-metadata macro to set the major and minor versions. Major version incremented on approval of content, minor version on any update on the approved content
{description}
{state:Review|approved=Approved|taskable=true}
{approval:Review}
{state}
{state:Rejected|submit=Review|taskable=true}
{state}
{state:Approved|final=true|updated=Review|hideselection=true}
{state}
{trigger:pagecreated}
{set-metadata:currentversion}0.0{set-metadata}
{trigger}
{trigger:pageupdated}
{increment-metadata:currentversion|increment=0.1}
{trigger}
{trigger:pageapproved|approval=Review}
{increment-metadata:currentversion|increment=1.0}
{trigger}
{workflow}
Here's how each trigger action works.
Trigger Event | Action macro | Notes | Confluence and Metadata version displayed on content using |
---|---|---|---|
|
| o | |
|
| Editing the page updates both the
| |
|
| On approving the page and transitioning to the Approved state the
| |
|
| Editing the page in the Approved state
| |
|
| Editing the page in the draft Review state, with a previously approved version
| |
|
| On approving the page and transitioning to the Approved state the
|
An individual reviewer rejection decision on its own does not impact the metadata currentversion
value.
Manage composite major-minor-patch version of the content
Additional triggers may be useful to initiate major-minor-patch value changes.
This second example below uses the increment-metadata macro to support the custom versioning of a page using a composite numeric metadata value.
The elements of the composite version are incremented when different specific events occur.
{workflow:name=Composite Increment Metadata}
{state:Draft|submit=Review}
{state}
{state:Review|approved=Approved}
{approval:Review|assignable=true}
{state}
{state:Approved|final=true|submit=Draft}
{state}
{trigger:pagecreated}
{set-metadata:comp-version}
0.0.1
{set-metadata}
{trigger}
{trigger:pageupdated}
{increment-metadata:comp-version|increment=0.0.1}
{trigger}
{trigger:statechanged|state=Review}
{increment-metadata:comp-version|increment=0.1.0}
{trigger}
{trigger:statechanged|state=Approved}
{increment-metadata:comp-version|increment=1.0.0}
{trigger}
{workflow}
The metadata name and initial value are set on the creation of the page using a trigger macro and the set-metadata action macro.
{set-metadata:comp-version}0.0.1{set-metadata}
A version change will occur:
for every page edit (a PATCH version change)
on a state change to the Review state(a MINOR version change).
on a state change to the Approved state (a MAJOR version change).
Metadata value initialization
Page creation creates the metadata comp-version
and sets the initial value as 0.0.1
{set-metadata:comp-version} 0.0.1 {set-metadata}
Minor element value update
A state change to the Review state updates the second numeric version element (MINOR element) by 1.
The workflow uses a trigger macro on the statechanged
event for state=Review
and the increment-metadata action macro.
{increment-metadata:comp-version|increment=0.1.0}
Major element value update
A state change to the Approved state will update the first numeric version element (MAJOR element) by 1.
The workflow uses a trigger macro on the statechanged
event for state=Approved
and the increment-metadata action macro.
{increment-metadata:comp-version|increment=1.0.0}
Patch element value update
A page edit will increase the final numeric version element (PATCH element) using a trigger macro listening for the pageupdated
event and using increment-metadata action macro.
{increment-metadata:comp-version|increment=0.0.1}
Setting the metadata value when using a content label filter workflow
If the workflow uses a content label filter, and the label to filter the workflow application is added after the page is created, using a pagecreated
trigger to set the metadata value is not appropriate as the workflow is added and applied by the label addition after the page is created.
In a content label filter workflow, the following trigger can be used to set the currentversion metadata value.
The trigger fires only on the first transition of the page to the Draft state. This is because the trigger includes the initial=true
condition parameter.
The metadata is then incremented in the final workflow state
In this example, the trigger action macro increments the currentversion metadata value by one for its major version.