Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Problem getting a macro parameter Edited

<xhtml-macro name="clientinfo" key="clientinfo"
                 class="com.atlassian.confluence.plugins.clients.ClientinfoMacro">
        <description>A macro that extracts the client information from a JIRA issue and returns it as a JSONObject.
        </description>
        <category name="admin"/>
        <parameters>
            <parameter name="issuekey" type="string" default="CI-02" required="true"/>
        </parameters>
    </xhtml-macro>

    <xhtml-macro name="printinfo" key="printinfo"
                 class="com.atlassian.confluence.plugins.clients.PrinterMacro">
        <description>A macro that prints out the information from the fields in a JIRA issue.</description>
        <category name="admin"/>
        <parameters>
            <parameter name="add" type="string" default="City"/>
        </parameters>
    </xhtml-macro>

So this is part of my atlassian-plugin.xml
As you can see I have 2 macros here, the 1st one I use to get the information from a JIRA issue and put it in a context, and the 2nd should get information from that context, the idea being not to make 1000 requests to JIRA so as to get the info from each field.

public class ClientinfoMacro implements Macro {

    @Override
    public String execute(Map<String, String> params, String arg1, ConversionContext conversionContext)
            throws MacroExecutionException {

        String key = params.get("issuekey");
        Hashmap<String, String> map = new FieldMap().parse(fields);
        conversionContext.setProperty("fieldMap", map);
        conversionContext.setProperty("issueJson", issue);

 

This is how I get the parameter in the 1st macro (params.get("issuekey")) and it works. I've also included the properties I pass to the 2nd macro.

public class PrinterMacro implements Macro {

    @Override
    public String execute(Map<String, String> params, String s, ConversionContext conversionContext)
            throws MacroExecutionException {

        String add = params.get("add");
        HashMap<String, String> fieldMap = (HashMap<String,String>)conversionContext.getProperty("fieldMap");
        JSONObject issue = (JSONObject)conversionContext.getProperty("issueJson");

That's how I try to get the parameter in the 2nd macro (params.get("add")), but for some reason it doesn't work. I cast the properties from the conversionContext properly, I've checked, but for some reason the add parameter is null, despite of me typing in it's field.

 

java.lang.NullPointerException
   at com.atlassian.confluence.plugins.clients.PrinterMacro.execute(PrinterMacro.java:34)

34->  System.out.println("prop id: "+fieldMap.get(add));

Any idea as to why I can't get the parameter in the 2nd macro?

 

 

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
import org.apache.commons.lang.StringUtils;

String key = StringUtils.defaultString(params.get("issuekey"), "CI-2");
String add = StringUtils.defaultString(par.get("getfield"), "Client Type");

After some time spent on BitBucket going through other people's code I saw they used StringUtils and when I tried it, it worked. Now both parameters return the correct value.

For anyone wondering why this fixes it, default values defined in the plugin .xml aren't actually passed to the macro if they are selected, so you have to provide the default value server side in code. 

Like Lukas Gotter likes this
TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

235 views 5 13
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you