Unlabel specific page after page move
Asked by Nathan Ell:

Using Confluence automation, how would one set up a rule to:

* For pages that:
  * Exist as a child of a page with a specific title,
  * Have a specific label on them,
* When the page moves,
* Remove a specific label


Answers:
author: Nicolas Tagle
body: Hi Nathan,

There surprisingly scare information regarding the usage of CQL imho. I was not successful on finding a way to trigger automation with the trigger "Move" page, but I found that if you make the trigger run on Edit OR if you schedule it to run once a day in the following CQL condition

space = "\~5cbf3cc8c4966f0ffe44b985" and label IN ("automation") and ancestor in(2341897092)

You will find that it accomplish almost the same outcome. It will looks like this:  

![1.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/247111i67E30976EAFC09D3/image-size/large?v=v2&px=999 "1.jpg")

If you grab the link to your parent page you can find the space id and the Ancestor page id :

<https://xxxxxxxx.atlassian.net/wiki/spaces/>\<space ID\>/pages/\<Ancestor page ID\>/\<Ancestor Title\>.

Let me know if this was useful!

Cheers,

Nico.

comments: author: Nathan Ell
body: Hey Nico,

Thanks so much for the comment. It looks like I'm about 95% there. I tried implementing a version of this for some testing (use case: if a page is a child of a certain other page, and it has the "rca" label, then remove the "rca" label):

![confluence.png](https://community.atlassian.com/t5/image/serverpage/image-id/247596iF06851ABED5A15D0/image-size/large?v=v2&px=999 "confluence.png")

When I validated that CQL, it confirmed the query was valid and that 19 contents were found (which matches what I expect). However when actually *running* this rule, I get an error:

```
No CQL-compatible content found in the rule context; there is nothing to check against the CQL query. The CQL condition component can only follow components that involve CQL-compatible content, such as the blogpost published trigger, the publish new page action, or the related entities branch.
```

I also implemented a rule closer to your original suggestion (use case: if a page is a child of a certain other page, and does not have the "rca" label, then add the "rca" label):

![confluence2.png](https://community.atlassian.com/t5/image/serverpage/image-id/247598iDD5BA1707355C2FB/image-size/large?v=v2&px=999 "confluence2.png")

This had the same problem - while the CQL condition *did* validate successfully and return the expected number of pages, it did *not* run successfully and gave the same error message.

In both cases the rule was (as you can see) set up on a scheduled trigger, but I just ran it manually using the "Run rule" button to force an immediate run.

Would appreciate if you have any thoughts!


author: Nathan Ell
body: Interestingly, I noticed that if I change the trigger from Scheduled to Page edited, the rule runs just fine on the page that got edited


author: Nathan Ell
body: The use case for my "remove the "rca" label from pages with a certain ancestor" rule is that I have a bunch of pages that get moved (not archived in Confluence terms) to a different ancestor annually. One of two things needs to happen - either:

* On move of the page to a different, known ancestor, the "rca" label needs to be removed. The "Page edited" trigger does not appear to be triggered when a page is *moved*, only if the content is changed, so the rule does not trigger.
* On a schedule, if a page has a certain ancestor and has the "rca" label, then remove the "rca" label.

I belive that in Jira automation, I would be able to accomplish the latter by inserting an action of "lookup issues", then a branch applying to all issues found, with an action of "do something" - but it seems like in Confluence I don't have the ability to "lookup pages", "for each page", "remove label"


author: Nicolas Tagle
body: Hi Nathan,

I haven't had the time to test it but if the trigger "schedule " does not work and "Page Edit" does, seems like a bug to me. I 'll update you if I found any new information regarding this when I can test it out myself, in the meantime I suggest you check the feedback platform from Atlassian and evaluate submitting a bug here <https://jira.atlassian.com/browse/CONFCLOUD>.

Cheers!

Nico.


author: Trev Angle
body: Hi [@Nathan Ell](/t5/user/viewprofilepage/user-id/2986288) and [@Nicolas Tagle](/t5/user/viewprofilepage/user-id/4680848), Trevor here from the Confluence automation team. Unfortunately the documentation around the CQL automation components is in need of an update, but I think I can explain what's going on here.

It is expected that an error will happen when the CQL condition is used immediately after a scheduled trigger. The condition operates by checking whether the content referenced in the rule matches the provided CQL query. If the content referenced in the rule is matched by the CQL query, the rule continues. If not, the rule stops executing. In the case of the scheduled trigger, *there is no particular content being referenced*, so the condition has nothing to check. This is why an error occurs.

I suspect that the component you want to use in combination with the scheduled trigger is really the "Branch rule / related entities" component. Think of this branch component as being a way to 'search' for any CQL content you want. It doesn't depend on any content being referenced previously in the rule, so you can use it with the scheduled trigger.

By the way, totally open to suggestions around how we can improve the error messaging to reduce confusion!


Tags: automation

cloud

confluence-cloud

cql