way to get login id and pass as query string in confluence?

Hi, I am looking for the option to get user login id and pass the value to query stirng to url .

help please?



4 answers

the below code is working to get user login id with confluence 5.1.3:

<script type="text/javascript">



&lt;script type="text/javascript"&gt;
var init = 0;   
function download() 
var url = document.getElementById("dload_frame").src;  
var userEmail;
var userlogin = AJS.Data.get("remote-user"); 

var userName= AJS.Data.get("user-display-name");  
var arr=userName.split(",");  
var Firstname=arr[1];
var Lastname=arr[0];
userEmail = userlogin+"@xyz.com"    ;
var url1="http://www.abc.com?firstname=" + Firstname + "&amp;lastname=" + Lastname + "&amp;email="+ userEmail; 
document.getElementById("dload_frame").src = url1; 

&lt;iframe id="dload_frame" src="" width="800" height="400" frameborder="0" scrolling="no" &gt; &lt;/iframe&gt;   
&lt;script&gt;   download();   &lt;/script&gt;

The provided code should be HTML macro. this code is to pass frist name, last name and email id from confluence logged in user and passing values to iframe url.

if you are tyring to get through jira api then use this


or if you are trying to get in JAvaScript then try with this

function getCurrentUserName()
var user;
        url: "/confluence/rest/prototype/1/user/current",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
     return user;

and check this post


Hi Prasad, Thans for the prompt reply.

can you also let me know the variable to get user's firstname and lastname?

My idea is to get everyting done through HTML code in confluence. Basically this HTML code will get the user login id and pass that value to querystring of the url in iframe tab.

will the above suits for my requirement? please suggest.



check now i have updated my answer!

Hi Prasad, thanks again!

I have just tried above provided code by placing between <script language="Javascript"> </script>. i tried to display the user value using alert(user) instead. but code did not work . getting alert message 'undefined' after save the page.

below is the code i tried to put in HTML macro

 <script language="Javascript"> 

var user;
AJS.$.ajax({         url: "/confluence/rest/prototype/1/user/current",         type: 'get',         dataType: 'json',         async: false,         success: function(data) {             
user = data.username;

did i place something wrong? please help me this non-programmer.

or guide me how to use AJS.params.loggedInUser in script?



try with this

&lt;script type="text/javascript"&gt;
&lt;script type="text/javascript"&gt;

Both the cases i end up with alert which says 'undefined' . No luck :-(



Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

118 views 2 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot