I’ve managed to add a new parameter and the following Javascript file gets deployed when I upload my plugin:
AJS.MacroBrowser.setMacroJsOverride("example-formatting", {
fields: {
string: {
"willbehidden": function (param) {
var parameterField = AJS.MacroBrowser.ParameterFields["_hidden"](param, {});
if (!parameterField.getValue()) {
parameterField.setValue('hidden field value');
}
return parameterField;
}
}
}
});
However, when I pick my macro from the macro browser the console keeps giving me such an error:
Failed to run init function: AJS.MacroBrowser is undefined
function () TypeError: AJS.MacroBrowser is undefined
I’ve also tried to wrap the JS code into this block, which is not included in the tutorial code, but elsewhere it’s described as being mandatory:
AJS.toInit(function(){
// above code
});
However, this does not resolve the issue, even though AJS.MacroBrowser is available to me in the console. Purging the browser cache doesn’t help. I’m totally stuck and would appreciate any help.
Now the error is gone, but the JS code has zero effects I’d expect the hidden field to actually get hidden, but it’s still there. Also, I would expect the field to get hidden if I just execute the whole command in the console, but nothing happens.
Oh! This is so frustrating
I wasted hours only to find out that AJS.MacroBrowser.setMacroJsOverride(macro, func) takes the xhtml-macro name as its first argument, not the key!
We haven’t found the root cause, but in case you refer to the context of macro-browser like this → requireResourcesForContext("macro-browser")(in my case, I refer this in velocity templates). Probably you can try to delete it and just call the AJS.MacroBrowser as it has been exported globally. My plugin works again after I stop requiring the macro-browser context, but still figuring out why is that.
I’m using AJS.MacroBrowser in one of the custom plugin that we built. It was working fine till confluence 7.19.8 version. We just upgraded our instance to 8.5.2 , started facing the same issue .
Failed to run init function: AJS.MacroBrowser is undefined
function () TypeError: AJS.MacroBrowser is undefined
As per my knowledge, we no longer need to import the macro-browser context such as requireResourcesForContext("macro-browser") due to AJS.MacroBrowser has been exported globally. I tried it last time at Confluence 8.0 but I haven’t try it on 8.5.2.
If you import the macro-browser explicitly, you can try to remove it and see if it works.
Thanks for the reply and looking into it. I’m not importing the macro-browser explicitly… I’m directly calling AJS.MacroBrowser function in my JS file but still error exists. It was working fine in 7.19.8 but after 8.5.2 upgrade ,I’m getting this error.
This is my Plugin JS code …
(
function($) {
var custommacro = function() {};
var fileurl;
var frameElement;
console.log('inside cjs file');
custommacro.prototype.fields = {
"string": {
"code": function(param) {
var parameterField = AJS.MacroBrowser.ParameterFields["_hidden"](param, {});
console.log('parameterField:' + parameterField)
if (!parameterField.getValue()) {
parameterField.setValue('');
}
return parameterField;
},
"url": function(param, options) {
console.log('inside fileurl funcation');
var paramDiv = AJS.$(Confluence.Templates.MacroBrowser.macroParameter());
paramDiv.empty();
var input = AJS.$("#macro-param-div-url", paramDiv);
//Calling a function which returns the iframe and append it ..
return new AJS.MacroBrowser.Field(paramDiv, input, options);
}
}
};
custommacro.prototype.beforeParamsSet = function(selectedParams, macroSelected) {
fileurl = selectedParams.url;
console.log('url:' + fileurl);
return selectedParams;
};
custommacro.prototype.beforeParamsRetrieved = function(params) {
params.fileurl = $("#macro-param-url").val();
console.log('fileurl' + fileurl);
console.log('insidebeforeparamretrieved');
return params;
};
AJS.MacroBrowser.setMacroJsOverride("insert-link-file", new custommacro());
})(AJS.$);
I’m not using require JS in my code. Do you mean going forward I’ve to use required.JS in confluence 8.5 version onwards ? Could you please elaborate more on the issue you see in the code ? I’m newbie in JS programming…