Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get username using Javascript

Ron Linder April 3, 2018

Is there a way to get the username via javascript code? Or a way to store the User Name macro into a JS variable?

2 answers

1 accepted

1 vote
Answer accepted
Ron Linder April 3, 2018

OK managed to do it via ajs.params.remoteUser, but I get the ID of the user not the name...

 

OK solved, its ajs.params.userDisplayName

Susan S.
Contributor
May 23, 2018

I am trying to do something similar for an analytics profile. How did you code the parameter?

Like • joe percival likes this
Ron Linder May 24, 2018 edited

Here is a sample:

<body>
<script type="text/javascript">
AJS.toInit(function(){ 
alert("ID: " + AJS.params.remoteUser.toUpperCase() + " | UserName: " + AJS.params.userDisplayName + " | PageID: " + AJS.params.pageId); 
}); 
</script>
</body>

Place this into an HTML macro...

Susan S.
Contributor
May 24, 2018

So I was able to use that variable to get this:

var remoteUser = AuthenticatedUserThreadLocal.getUsername();
_paq.push(['setUserId', 'xxx']);
_paq.push(["setCustomVariable", 1, "username", remoteUser, "visit"]);

However, I am at a loss a since I need to acquire username in DN form for the UserID.

Ron Linder May 24, 2018

It looks like you are trying to write variables rather than read variables...that I haven't tried yet.

Like • joe percival likes this
Susan S.
Contributor
June 3, 2018

That method only works in older versions since the newer versions disable AJS.

var user = AJS.Meta.get("remote-user");
var userdn = AJS.params.userDisplayName;
var userremote = AJS.Meta.get("remote-user");

Like • 2 people like this
0 votes
Christopher Siebert
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 21, 2018 edited

Here is what I use:

var userFullname = $("#user-menu-link").attr("title");

Your mileage may vary depending on how your Confluence is configured.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events