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, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events