Set dynamic macro parameters for enum type

I am quite new to implement confluence macros.

Requirement is to set dynamic parameter values for the 'enum' field type in the macro browser.

I followed https://community.atlassian.com/t5/Answers-Developer-Questions/How-can-i-set-dynamic-values-for-drop-down-enum-param-in-the/qaq-p/535124/jump-to/first-unread-message and

https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-implement-dynamic-macro-parameters-enumerations-in/qaq-p/463297

But end up with no success, it was not working for me. Seems some thing I was missing?

Please see my macro definition in atlassian-plugin.xml

<xhtml-macro name="xxxxxx"

title="xxxxxfunctionality"

class="xxxxxx.xxxxxx"

icon="xxxxx/xxxxxxx/${project.groupId}.${project.artifactId}/xxxx/xxxxxxxx.png"

key="xxxxxxxxx-macro">

<description key="xxxxxx.macro.desc"/>

<category name="development"/>

<parameters>

<parameter name="xxxxx" type="enum" required="true" default="None">

</parameter>

</parameters>

</xhtml-macro>

And the JS file here:

(function ($) {

console.log("js file called");

var xxxxxxMacro = function () {};

console.log("js file called 2");

xxxxxxMacro .prototype.fields = {

"enum": {

"xxxxx": function (param, options) {

console.log("js file called 3");

var paramDiv = AJS.$(Confluence.Templates.MacroBrowser.macroParameterSelect());

var xxxxxDropDown = AJS.$("xxxxx", paramDiv);

console.log("inside enum group");

loadXxxxx(xxxxxDropDown);

return new AJS.MacroBrowser.Field(paramDiv, xxxxxDropDown, options);

}

}

};

 

function loadXxxxx(xxxxxDropDown){

console.log("js file called 4");

xxxxxDropDown.empty();

xxxxxDropDown.append($("<option>color1</option>"));

xxxxxDropDown.append($("<option>color2</option>"));

console.log("call complete");

}

 

AJS.MacroBrowser.setMacroJsOverride("xxxxxxxxx-macro", new xxxxxxMacro());

})(AJS.$);

 

Please help me regarding this.

1 answer

something like this should work

"xxxxx": function (param, options) {

param.enumValues = ['color1', 'color2'];

//in Confluence 6.6+ you need to specify displayed values, otherwise all dropdown items are displayed as "undefined"
param.enumMapValueName['color1'] = 'color1'
param.enumMapValueName['color2'] = 'color2'

return AJS.MacroBrowser.ParameterFields['enum'](param, options);
}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

385 views 21 10
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you