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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published yesterday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

68 views 0 9
Read article

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