How to get page id of published page in automation
Asked by Julio Verano:

I am creating an automation rule that creates a page from a template when another page is created (from a specific template) and as a child page.

I am able to create the automation rule and it functions as intended for everything above ***except*** creating the new page (lets call this page "b") under the original page that was created and that triggered the automation (let's call this page "a").

I know the publish new page action does not support creating ***under***the page that triggered the automation BUT I am able to work around that gap by interacting with the confluence rest api through the "send web request" action. I also have the send web request action working, however I need to reference the original page id (page "a") to set as the parent for the new published page (page "b").

I see in the audit log there is a link to associated items which includes the published page.

Is there a smart value I can reference to get the page id of that newly published page in the automation (page "b" in the example above)?


Answers:
author: Tim Kopperud
body: Hi [@Julio Verano](/t5/user/viewprofilepage/user-id/5080903), if I understand your question correctly and page A is the page that trigger the rule and you create page B within the rule, you can use this smart value to fetch page As ID.

```
{{page.id}}
```

TimK.

comments: author: Julio Verano
body: Thanks Tim for the response!

Actually its the id of the new page created in the automation (page B in my example above) that I am needing to complete this automation - is there a smart value for that?


author: Tim Kopperud
body: Hi [@Julio Verano](/t5/user/viewprofilepage/user-id/5080903), I have looked deep into this to see if it's solvable.

It seems the page is created long after the rule is completed. Even trying to use webhook to another rule (rule 2) doesn't work because the page published in rule 1 is not even created when reaching rule 2. This concludes that you are not able to fetch the page id for any pages published within a rule. At last, this is how I understand it.

The only idea I have to solve this is as follows:

You will need three rules for this approach, which are all triggered by **When: Page published**.

**Rule 1 - for creating page B** {#toc-hId--413275598}
------------------------------------------------------

First, add a filter needed for your scenario so you don't hit all published pages, but only those needed.

Add action **And: Publish a new page**, and use a template that contains the label "autocreated_page_b".

**Rule 2 - for moving page B, creating page C and remove label** {#toc-hId-2074237235}
--------------------------------------------------------------------------------------

Start with a filter **If: Compare two values** configured as

* **First value =**{{page.label}}
* **Condition =**equals
* **Second value =**autocreated_page_b

Then add action **And: Publish a new page**, use a template that contains the label "autocreated_page_c".

Create action **Then: Remove label** to remove "autocreated_page_b" from this page as it's not needed any more.

Since you now have the id from page B, using {{page.id}} here in rule 2, you can execute the move of page B using the REST API you mentioned.

**Rule 3 - for moving page C and remove label** {#toc-hId-266782772}
--------------------------------------------------------------------

Start with a filter **If: Compare two values** configured as

* **First value =**{{page.label}}
* **Condition =**equals
* **Second value =** ++autocreated_page_c++

Create action **Then: Remove label** to remove "autocreated_page_C" from this page as it's not needed any more.

Since you now have the id from page C, using {{page.id}} here in rule 3, you can execute the move of page C using the REST API you mentioned.

Note {#toc-hId--1540671691}
---------------------------

You will need to add labels to your two templates fpr page B and page C up front. You might swap the label names I have used to your own desire.

Since the templates contains labels that passes the filters in rule 2 and 3 you must either

* secure that the two templates are not used for other purposes, or
* add addition logic to the filter e.g., add creator equals the ruleowner and/or created within the last minute \[ *created \<= now("-1m")* \] etc.

TimK.


Tags: cloud

confluence-cloud