How can I change the output of a confluence user macro to be an Integer?

Eric Monfette November 12, 2019

I need to change the output of a user macro to be an Integer or String depending on use. How can I set the output to be "86" instead of an "86 issues" link to jira. Created the user macro linked below in article. Edited macro to output just have count of issues as a jira link. Any direction on how to display results of JQL query as string in confluence would be great.

https://community.atlassian.com/t5/Confluence-questions/Using-template-variables-as-input-parameters-to-jira-gadget/qaq-p/189292

1 answer

1 vote
Sven Schatter _Lively Apps_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
November 13, 2019

Hi Eric,

Two things worth mentioning:

  • You can't change the output type of macros. Macros always return a String. Of course the String could contain only a number but if we're talking about data types it is still a String.
  • The examples you linked to use Confluence default macros such as "jira" or "jiraissues". Therefore you don't really have control over their output.

I see a few possible solutions to your problem here:

  • You could build your own user macro that doesn't rely on a Confluence default macro and instead makes the request itself. (Could be quite complex and requires good user macro programming knowledge on your part)
  • You could include some JavaScript in your user macro that removes the " issues" part from your result so only the numbers stays. (Probably way simpler, but very janky and generally not advisable)
  • You could use a third party solution like our app PocketQuery. In PocketQuery you could simply set up a JQL REST query that fetches your data. You can then write a velocity template for it that defines how the data should be rendered. In your case this should be very simple. And since you're already building complex user macros to begin with you might find that PocketQuery will make your life a lot easier in many other situations where you want to show data from external sources as well. If you want to give it a shot and have any questions you can always ask our support. We're happy to help! :)

Best regards,
Sven

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events