Hi.
I'm following the same code I've found in other sites to check the groups for the current user (namely on http://www.j-tricks.com/1/post/2012/02/some-ajs-tricks.html) in Confluence and the following render error is always returned: "Error rendering macro 'macro-name' : Error occurred rendering template content".
Here's the script:
AJS.toInit(function() {
var username = getCurrentUserName();
(... some more script ...)
});
function getCurrentUserName() {
var user;
AJS.$.ajax({
url: "/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.username;
}
});
return user;
}
I debugged the script and the error happens on the AJS.$.ajax call. I tested the URL directly to check if the current user info is being returned and it is.
Tried some alternatives, but without any luck. The error happens everytime the AJS.$ is called. If I remove that block everything works fine.
Does anyone has some suggestion on how to solve this (or bringing me a bit closer to the solution)?
Thank you.
Hi,
I've used AJAX in a user macro as I use it to pull in a 'feedback' button which launches a JIRA issue collector. The thing I found is that you can't use $.ajax for some reason but using jQuery.ajax did work. E.g.:
<script type="text/javascript"> AJS.toInit(function(){ jQuery.ajax({ ... }); }); </script>
Hope this helps.
Steve - thank you so much!
I now have this working with a get and post.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Zezeto. Thanks for your comment. The example is for JIRA, true, but if I make the call on the browser it results the information about the current user. I took that if it results the information the example should work as well in Confluence.
But I used as well the Confluence REST URL to get the current user information and it returns the information with sucess on the browser not on the script. Even tried with the full URL, but to no avail...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think this example http://www.j-tricks.com/1/post/2012/02/some-ajs-tricks.htmlworks only in JIRA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try with this script
<script type="text/javascript"> (function($) { AJS.toInit(function() { var username = getCurrentUserName(); alert('loggedin user: '+username); }); function getCurrentUserName() { var user; AJS.$.ajax({ url: "../rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; } })(AJS.$); </script>
or tey with following script
<script type="text/javascript"> AJS.toInit(function(){ alert(AJS.params.remoteUser); }); </script>
check this dco for more info
https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluence
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot for your prompt answers guys. Unfortunately the error continues...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you share your code ?
how you are adding javascript on confluence?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well... is prety much as I wrote in the post and it's inside a macro. The rest of the script is just code to show a popup window. The idea is to show the popup just when the user belongs to a specific group. That's why I picked up this example, it would work just fine with the rest.
I even tried with the '/rest/prototype/1/user/current' URL (got it from the Confluence REST API documentation) and it works just fine on a direct call in the browser.
The problem is really the use of the AJS.$ on the script and I can't understand why. If I add the AJS.$.ajax it results the error (even without setting any parameters), I remove it and everything works...
Am I missing some assembly call or something? Is there any other way to get the current user and the groups to which he belongs? I am pretty new working with the Confluence API, so some things just surpass me...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i have updated my answer!! try with that!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Did you get this working as I am facing the same issue when using AJS.$.post in a Confluence User Macro.
Is the use of AJAX in a user macro not supported?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Add to your url contextPath it will be like this
url: contextPath+"/rest/gadget/1.0/currentUser"
function getCurrentUserName(){ var user; AJS.$.ajax({ url: contextPath+"/rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.