way to get login id and pass as query string in confluence?
Asked by Lakshmi:

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

help please?

Thanks,

Laskhmi


Answers:
author: Lakshmi
body: the below code is working to get user login id with confluence 5.1.3:

<br />

\<script type="text/javascript"\>   

alert(AJS.Data.get("remote-user"));   

\</script\>  


author: Lakshmi
body: ```
&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;/script&gt;     &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.
```

```
?
```


author: RambanamP
body: try with this

```
&lt;script type="text/javascript"&gt;    alert(AJS.Meta.get("ajs-user-display-name"));    alert(AJS.Meta.get("ajs-remote-user"));&lt;/script&gt;or &lt;script type="text/javascript"&gt;    alert(AJS.params.loggedInUser);        alert(AJS.params.remoteUser);&lt;/script&gt;
```

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

Thanks,

Lakshmi


author: RambanamP
body: if you are tyring to get through jira api then use this

```
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
```

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

```
AJS.params.loggedInUser orfunction getCurrentUserName(){var user;     AJS.$.ajax({        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

https://answers.atlassian.com/questions/167046/expose-the-value-of-action-remoteuser-name-to-javascript?page=1

comments: author: Lakshmi
body: 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.

Thanks,

Lakshmi


author: RambanamP
body: check now i have updated my answer!


author: Lakshmi
body: 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.

<br />

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;}}); alert(user);        </script> ``` |

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

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

Thanks,

Lakshmi


Tags: login

query