My template variable in a custom JQL user macro does not render more than once, why not?
Asked by Christopher Parsons:

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

<br />

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"
```

<br />

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.


Answers:
author: Fabian Lim
body: Hi [@Christopher Parsons](/t5/user/viewprofilepage/user-id/1197563)

Can you please share the screenshots to have a full context of your issue?

Thanks

comments: author: Christopher Parsons
body: Hi [@Fabian Lim](/t5/user/viewprofilepage/user-id/3131564) ,

Thank you for the response. After some further debugging, we were actually able to get this figured out. It seems a copy and paste of the previous JQL might be introducing either some hidden characters or maybe a different type of text encoding that the macro did not like

We learned typing the JQL query again from scratch seems to have fixed the issue despite the text looking identical in the GUI.

I am not at my computer currently but I will update this post later with some screenshots in case it's helpful to others in the community.


Tags: confluence-server

jql

server

template

user-macro