Confluence automation - Check if all tasks on page have been complete and edit status macro
Asked by Harry Lee:

Hi all,

I'm trying to create an automation that will edit the status macro on a page when all the tasks on said page have been completed.

Is this possible?

Thank you!


Answers:
author: Andrii Maliuta
body: Hello [@Harry Lee](/t5/user/viewprofilepage/user-id/4209068) ,

Technically this is possible: it is up to you how to do it:

* ScriptRunner script / listener
* Custom listener for a page update
* Custom code executed in some environment that checks page body via REST API and does its job when the criteria are met

I suppose the general approach would be to run the code when the new version is created (when checkbox is ticked, it creates a new page version) and parse page body to check if all the get all tasks from xHTML/HTML and if all tasks have '**complete**' status that is set as the xhtml attribute:

```
<ac:task-status>complete</ac:task-status>
```

```
<ac:task>  <ac:task-id>2</ac:task-id>  <ac:task-status>complete</ac:task-status>  <ac:task-body><span class="placeholder-inline-tasks"><ac:link><ri:user ri:account-id="xxx" /></ac:link> task here <time datetime="2023-09-28" /> </span></ac:task-body></ac:task>
```

If all the \`\`\` ac:task \`\`\` elements have **complete**status then you can update the page and update the Status macro inner code (\<ac:parameter ac:name="title"\>resolved\</ac:parameter\>).

```
<ac:structured-macro ac:name="status" ac:schema-version="1" ac:macro-id="c0849f79-ce68-46ba-8539-088974fc596a"><ac:parameter ac:name="title">resolved</ac:parameter></ac:structured-macro>
```


author: Kathy Hart
body: Is this possible using the built in Confluence Automation, or is it only possible with Scriptrunner or Forge?


author: Harry Lee
body: [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201) - That makes sense in theory. How would one check if all ac;task status have been checked?

comments: author: Andrii Maliuta
body: Please re-read the whole comment.
> If all the \`\`\` ac:task \`\`\` elements have **complete**status then you can update the page and update the Status macro inner code (\<ac:parameter ac:name="title"\>resolved\</ac:parameter\>).

If the child parameter of the element contains 'resolved'.


author: Harry Lee
body: [@Andrii Maliuta](/t5/user/viewprofilepage/user-id/484201) apologies, I meant would you use an automation within confluence automation such as the send web request? I'm new to utilising the REST api so trying to learn as much as I can!


author: Andrii Maliuta
body: Hi [@Harry Lee](/t5/user/viewprofilepage/user-id/4209068) !

I suppose that the options are:

* To listen for a page edit and check its body each time - if all the checkboxes are marked, then you can do the necessary work
* Create a standalone app that will run as a separate service and will check for pages bodies that you need (by CQL query, or space level, or by IDs) - it will trigger checking data by REST API and then perform what is needed

If I am not mistaken, usually **Script Runner** app ([https://marketplace.atlassian.com/apps/1215215/scriptrunner-for-confluence?hosting=cloud\&tab=overview](https://marketplace.atlassian.com/apps/1215215/scriptrunner-for-confluence?hosting=cloud&tab=overview) ) is used for the easy of automation as it has built-in listeners, behaviors, jobs, etc.

Also, the custom addon can be created using Forge/ Atlassian Connect if you need some custom functionality.

Hope I did not confuse :)


Tags: cloud

confluence-cloud