---
title: "Use metadata to increment a content version"
canonical: "https://support.appfire.com/space/CDML/650315910/Use%20metadata%20to%20increment%20a%20content%20version"
format: markdown
---
> Macro (aura-html)


> Macro (excerpt)
> 
> Increment a composite version number for example, major.minor.patch metadata value each time a reviewer approves the content

## Overview

Different events can be used to increment a composite version number.

<span style="color: #172b4d">The workflow uses the following trigger actions</span>

- <span style="color: #172b4d">initialize a version value using the </span><span style="color: #172b4d">[set-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650251172)</span><span style="color: #172b4d"> macro</span>
- <span style="color: #172b4d">increment the version value using the </span><span style="color: #172b4d">[increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264)</span><span style="color: #172b4d"> macro using different triggers for each element of a composite version number</span>

<span style="color: #1d1c1d">You will need to refresh the page content to view changes in the metadata value if you use the </span><span style="color: #1d1c1d">[get-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649826804)</span><span style="color: #1d1c1d"> macro on the page to display the metadata value.</span>

> ℹ️ <span style="color: #333333">These examples only work when the workflow is applied as a space workflow. The space workflow must be active to listen for the </span>`pagecreated` event to initialize the metadata value.

## 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}
```

> 📝 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](https://appfire.atlassian.net/wiki/spaces/AWPD/pages/617495700) as the content filter workflow may be applied after the page has been created.

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**”.

![image](media://0c9dfe59-477c-42b9-bb01-84933d43dff3)

> ℹ️ The metadata **publishedversion** value is set using the [set-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650251172) macro.

> 📝 In the workflow page header added to the page as a table the **publishedversion** metadata value is retrieved by the workflow using `@publishedversion@`.

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.

![image](media://cfd13686-ae5c-4be8-a145-3a07648fcf45)

> ℹ️ These updates do not change the **publishedversion** metadata value.

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**.

![image](media://4a42b741-3589-4e8a-ae3e-d68474c1845e)

Editing the page in the **Approved** state transitions the workflow on the page back to the **Review** draft state.

![image](media://6e6f2108-9c2b-4339-ae9e-dcc5fe0dfd33)

Each subsequent approval of the page and transition to the **Approved** state increments the **publishedversion** value.

![image](media://62216901-9115-426b-be0e-29d5bc02b1aa)

> ℹ️ Choosing (view “**Approved**”) when in the draft **Review** state displays a Confluence version from Page History.

> 📝 The metadata value is linked to a page not a Confluence page version so when viewing a previous page version this will show the current metadata value. This is *NOT *the metadata value when the content was published.

## <span style="color: #1d1c1d">Composite major-minor version content</span>

```plaintext
{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}
```

> 📝 In our example, applying the space workflow to existing pages does not initialize the **currentversion **metadata value and subsequent use of the **currentversion** metadata in the `increment-metadata` macro does not work.

> ✅ Instead of using the[ pageheader](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650348817) macro in the workflow, the [get-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649826804) macro can be added to a page to retrieve and display the current value for metadata.

![image](media://a0fd7ca9-53b8-4dc3-9b91-d7b71cb775c3)

Here's how each trigger action works.

| Trigger[ Event](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649923526) | Action macro | Notes | Confluence and Metadata version displayed on content using `get-metadata` macro |
| --- | --- | --- | --- |
| `pagecreated` | [set-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650251172) | - <span style="color: #172b4d"> sets the metadata </span>`currentversion`<span style="color: #172b4d"> and initializes the value to 0.0 on the creation of the page</span><br>> 📝 This only occurs on the creation of a page if the workflow is applied in space mode. | ![image](media://017e1e9d-3353-4e8f-8c6a-2efde6e79d9d)<br><span style="color: #ffffff">o</span> |
| > ⚠️ Applying this workflow in ‘page mode’, the `pagecreated` trigger will never fire because the page is *created ***before** the workflow is applied. To use within a page workflow, the metadata value would need to be initialized using a different event trigger. |
| `pageupdated` | [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) | - increments the `currentversion` minor value by 1 each time the page is updated
- major value is not changed | ![image](media://c16ee4f9-7c6f-44cc-bf71-ac612d102758)<br>Editing the page updates both the<br>- Confluence version value
- metadata minor value of the `currentversion` metadata
  - increments the minor value by **1** |
| `pageapproved` | [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) | - increments the `currentversion` major value by 1 each time the content is approved and transitions to** Approved**
- minor value is reset to zero | ![image](media://01101ff0-b759-45d6-9cda-7e4e93619c64)<br>On approving the page and transitioning to the **Approved** state the `pageapproved` trigger<br>- increments by **1** the major value of the `currentversion` metadata
- sets the minor value to **0** of the `currentversion` metadata |
| `pageupdated` | [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) | - increments the `currentversion` minor value by 1 each time the content is updated
- major value is not changed | ![image](media://be3ae216-da15-43cc-ae53-3c95670616a8)<br>Editing the page in the **Approved** state<br>- transitions the `updated` page to the **Review** state
- updates the Confluence version
- increments the minor value by **1** of the `currentversion` metadata |
| `pageupdated` | [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) | - increments the `currentversion` minor value by 1 each time the content is updated
- major value is not changed | ![image](media://61ae5c73-7974-4439-9eca-6a95f4eba893)<br>Editing the page in the draft **Review** state, with a previously approved version<br>- updates the Confluence version
- increments the minor value by **1** of the `currentversion` metadata<br>> ℹ️ The minor version value in this example is the number of page updates since the last approved version. |
| `pageapproved` | [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) | - increments the `currentversion` major value by 1 each time the content is approved and transitions to** Approved**
- minor value is reset to zero | ![image](media://04f52287-84b1-446c-b660-d85ccc2857e5)<br>On approving the page and transitioning to the **Approved** state the `pageapproved` trigger<br>- increments by **1** the major value of the `currentversion` metadata
- sets the minor value to **0** of the `currentversion` metadata<br>> ℹ️ The major version value in this example is the number of times the page has been approved and published.<br>> 📝 In this example, a page in the **Approved** state always transitions to the **Review** state when the page is updated. This means in the example
> 📝 
> 📝 - the published version will always be a major version with no minor version (for example 2.0; 3.0; 4.0 etc)
> 📝 - the minor versions will only be displayed for the page in a draft state (for example (2.1; 2.2; 2.3 etc). |

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](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) 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.

```plaintext
{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}
```

> ⚠️ Only works if this example workflow is applied as a space workflow as the metadata value is initialized on the `pagecreated` trigger.

The metadata name and initial value are set on the creation of the page using a [trigger](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649859133)** **macro and the [set-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650251172) 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}`

![image](media://403caf96-7d18-4c9a-aada-8d71d3368439)

### 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](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649859133) macro on the `statechanged` event for `state=Review` and the** **[increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) action macro.

`{increment-metadata:comp-version|increment=0.1.0}`

![image](media://781cb73a-2b46-4db0-900a-54d021a4288c)

> 📝 This also resets the final numeric element to zero e.g. a *version value 2.1.3 changes to 2.2.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](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649859133) macro on the `statechanged` event for `state=Approved` and the [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) action macro.

`{increment-metadata:comp-version|increment=1.0.0}`

![image](media://934a9257-fa9a-4bd3-8c5b-fe6205e0fcef)

> 📝 This also resets the second numeric version element *and* the final numeric element to zero e.g. *the version 2.2.5 changes to 3.0.0.*

### Patch element value update

A page edit will increase the final numeric version element (PATCH element) using a [trigger](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649859133) macro listening for the `pageupdated` event and using [increment-metadata](https://appfire.atlassian.net/wiki/spaces/CDML/pages/650250264) action macro.

`{increment-metadata:comp-version|increment=0.0.1}`

![image](media://bab93a33-237e-4f22-b4a9-1f9bbfb8623b)

> 📝 The final numeric version element increments by 1 for a page edit in any of the workflow states.

## Setting the metadata value when using a content label filter workflow

> 📝 The above may not workflow when the workflow uses a content label filter and a different workflow trigger must be used to set the metadata.

> Macro (excerpt)
> 
> 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.
> 
> ```
> {trigger:statechanged|state=Draft|initial=true}
>     {set-metadata:currentversion} 0 {set-metadata}
> {trigger}
> ```
> 
> 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
> 
> ```
> {trigger:statechanged|state=Approved}
>     {increment-metadata:currentversion|increment=1}
> {trigger}
> ```
> 
> In this example, the trigger action macro increments the **currentversion** metadata value by one for its major version.

## Related examples

- [Requiring a parameter on an approval transition to set a condition for the trigger to increment metadata for one of major, minor or patch composite version](https://appfire.atlassian.net/wiki/spaces/CDML/pages/649661052)