I created the following user macro based on an excellent post in the community which allowed me to inject a "$pagecreationdate" variable into a JQL query wrapped inside of a custom user macro container. This proof of concept allows me to pull in a list of Jira issues which were in a specific status between "$pagecreationdate 07:00" and "$pagecreationdate 15:30", as an example.
My goal is to create a template using several of these custom macros, each responsible for generating a static list of Jira issues. This worked great for the first JQL query I entered into the $body of my user macro. However, when I added a second instance of the same macro along with a slightly different JQL query, I noticed the second template variable simply does not render the value that gets entered by the user.
Here is my user macro:
## This macro will not accept any parameters. It will simply be used as a container for accepting JQL queries with template variables.
## @noparams
#set ($body = $body.replaceAll("\Q<p>\E",""))
#set ($body = $body.replaceAll("\Q</p>\E",""))
#set ($body = $body.replaceAll("\Q<span>\E",""))
#set ($body = $body.replaceAll("\Q</span>\E",""))
#set ($body = $body.trim())
<p>
<ac:structured-macro ac:name="jira" ac:schema-version="1">
<ac:parameter ac:name="server">JIRA</ac:parameter>
<ac:parameter ac:name="columnIds">issuekey,summary,issuetype,created,updated,duedate,assignee,reporter,priority,status,resolution</ac:parameter>
<ac:parameter ac:name="columns">key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter>
<ac:parameter ac:name="maximumIssues">50</ac:parameter>
<ac:parameter ac:name="jqlQuery">$body</ac:parameter>
<ac:parameter ac:name="serverId">MY-SERVER-ID</ac:parameter>
</ac:structured-macro>
</p>
With this user macro, I create a simple template page with a variable named $pagecreationdate. My expectation is the user is prompted to enter $pagecreationdate just once when they instantiate the page. Within the container of my user macro, I have a JQL query as follows:
project = MYPROJECT AND status WAS IN ("In Progress", "Resolved") BEFORE "
07:00"
In the first container, $pagecreationdate renders just fine. If I add a second user macro either via copy/paste or by instantiating a net-new macro, the $pagecreationdate template variable will not render within the user macro container. Outside of the macro, the variable will render as many times as I need it to. It's only within the macro this becomes an issue.
If anyone can help clue me in on what's going on, it would be extremely helpful. I suspect I can simply create multiple user macros, call them different names and solve my problem this way. However, I'd be really surprised if I'm not able to re-use this code.
I can provide screenshots if you want to see exactly what this looks like. Essentially, from a user perspective, they access the Confluence page and are met with a "Create From Template" button. They click the button, it calls my template, prompts them to enter a date for $pagecreationdate and brings them to the page, preferably with the JQL queries rendered and ready to go.