Set dynamic macro parameters for enum type

rambabu patina
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2018

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

0 votes
Akshatha February 20, 2019

Hi Rambabu

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

0 votes
Yury Buzenets March 6, 2018

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);
}
Akshatha February 20, 2019

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. 

roosi-ann_tolgu_concise_ee November 18, 2019

It seems that enumMapValueName is deprecated, use enumToI18nKeyMapping.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events