Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is it possible to implement custom macro parameter types in Confluence?

Dennis Andersen
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.
March 14, 2016

According to this documentation, the following types are available when specifying macro information in your xml: 

  • boolean - displays a check box.
  • enum - displays a select field.
  • string - displays an input field (this is the default if unknown type).
  • spacekey - displays an autocomplete field for search on space names.
  • attachment - displays an autocomplete field for search on attachment filenames.
  • username - displays an autocomplete field for search on username and full name.
  • confluence-content - displays an autocomplete field for search on page and blog titles.

Using these I can get suggestions and quick searches when configuring spaces, pages, attachments and users for example. Is there any way to implement/override a method to provide a custom search/suggestion depending on a custom type.

As an example, imagine I want to add the type "label" as a macro parameter. Whenever a field marked label is being filled in a search would give suggestions as it would with users or spaces. 

Any ideas or is it just not possible? 

Dennis

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Robert Krause
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.
March 14, 2016

Hi Dennis,

you can do this manually using JavaScript, that you add to the context macro-browser.

 

AJS.MacroBrowser.setMacroJsOverride("my-macro-key", {
	beforeParamsSet : function (params) {
		// Initialize your inputs with custom code, e.g. typeahead, search	
		return params;
},
	beforeParamsRetrieved : function (paramMap, macro, sharedParamMap) {
		// Parse input so confluence can handle it, e.g. join values of a multi-select
		return paramMap;
}
});

Best regards,

Robert

Dennis Andersen
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.
March 14, 2016

Hi Robert, 

Thank you for your answer. I tried it out but it wasn't quite what I was looking for. The callbacks only seem to trigger when opening the editor or on a preview refresh. What I want is a callback when I change the value in the param input. 

 

I found that the special types have functions defined in AJS.MacroBrowser.ParameterFields, but I didn't manage to add my own callbacks for custom types there neither. 

Robert Krause
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.
March 15, 2016

We use the beforeParamsSet-callbacks to register our own event listeners on the input fields. We do this to add custom multi-selects to your macro configuration. We load the values for the input field with ajax, add the values to the input and register change listener to perform further processing of the input data.

1 vote
Alex Medved _ConfiForms_
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.
March 28, 2016

Hi Dennis

We use it a bit different

AJS.MacroBrowser.setMacroJsOverride("your-macro-key", {
  fields: {
    "string": function (param, options) {
      if (param.name == "serviceId") {
        return handleServiceIdLookup(param, options);
      } else {
        var paramDiv = $(Confluence.Templates.MacroBrowser.macroParameter());
        var input = $("input", paramDiv);
        if (param.required) {
          input.keyup(AJS.MacroBrowser.processRequiredParameters);
        }
        return AJS.MacroBrowser.Field(paramDiv, input, options);
      }
    }
  }
});

We have a "string" type macro param in atlassian-plugin.xml and then "override" the string type for our macro and catch only the one we want to override, passing the rest params of string type through the standard handler

 

So, in our case, for macro parameter called "serviceId" we call our own javascript

return handleServiceIdLookup(param, options);

Where we actually create a Select element and replace it

var paramDiv = AJS.$(Confluence.Templates.MacroBrowser.macroParameterSelect());
var select = AJS.$("select", paramDiv);
...
return AJS.MacroBrowser.Field(paramDiv, select, options);

we also, have own implementation for "AJS.MacroBrowser.Field" to capture the selections and values set. Something similar what Robert has suggested, but from a different angle

 

Hope, this helps...

Dennis Andersen
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.
March 30, 2016

Hi Sash, 

Thank you for your answer! I'll try out both suggestions and see what works best for my use case.

Sujana B June 27, 2019

Hi @Dennis Andersen ,

I have similar requirement where I need to autocomplete page title specific to a space. Could you please advice. Thank you!

Dennis Andersen
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.
July 1, 2019

AutoComplete the page title as in from within the Confluence Editor or as a parameter to a macro? The solutions here are ways to customize the macro fields within the macro browser so I guess it can be used to inject space names to a specific field. It's not something I've tried however. Not sure on how to modify the editor in the way you want though. My best advice would be to ask it as a seperate question to go get more relevant answers in that case! 

Cheers! 

Sujana B July 1, 2019

"AutoComplete the page title as in from within the Confluence Editor or as a parameter to a macro?" -- Yes.

https://community.atlassian.com/t5/Confluence-questions/Dynamic-Macro-parameters/qaq-p/1118309

I posted a separate question for this part as well, but didn't here any :) . Thank you!

Dennis Andersen
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.
July 1, 2019

I see! For your 2 requirements in that question I'd recommend using Alex's anwser above. 

In your macro, have a field named e.g. 'pagePicker' of type String, 

Modify the answer accordingly to find the parameter and when finding it, you'd need to maybe do a rest-call to find the pages of the current space, then present them in a dropdown below your field in the macrobrowser. Additionaly you'd have events for when one or more pages in this list are selected and modify the value accordingly.  Using the aui-dropdown is recommended since it would then follow the look and feel of the rest of the macrobrowser. 

 

You'd do a similar thing for a field to verify if it's a number using javascript, since there's no int/Number type for macro parameters if I'm remembering correctly. 

Since Atlassian 'only' provides this JS-override method as far as I know you'd need to implement all of it manually to get it to work. 

Best of luck! 

Sujana B July 1, 2019

I would try that, Thank you for the answer!

TAGS
AUG Leaders

Atlassian Community Events