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

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.

2 answers

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);
}

I am also trying to achieve dynamic population of the drop down values. Tried above code which u mentioned. Still I am getting the values as undefined. 

Hi Rambabu

Was the issue resolved? Are you able to populate enum values dynamically?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

Confluence Server & Data Center 7.0 is here!

Hello Community 👋🏼 I’m Makisa, a product manager on Confluence Server and Data Center. Confluence Server & Data Center 7.0, our latest platform release, is now available and we wanted to shar...

157 views 0 11
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