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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

967 views 23 12
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