The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How to generate Dynamic URL link base on login user information

Michael Niu
February 26, 2014

Hi All,

I have to generatate a dynamic url link on my wiki page. it will like :

use login user infomation to get the parameter of the url from another database and generate it.

for example :

login user is smith , the url will be :

https://www.example.com/mypage.aspx?user=smith && pagenumber=33

login user is Don the url will be :

https://www.example.com/mypage.aspx?user=smith && pagenumber=36

Any suggestion is appreciatged

Regards

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 27, 2014

Here is some rough code. You would need to wrap it in a html macro.

<script type="text/javascript>
AJS.toInit(function(){
    var user = AJS.Meta.get('remote-user');

    AJS.$.ajax({
        type: 'GET', //or POST
        url: 'Your URL', //this should pass back the parameter based on the user submitted to it
        processData: true,
        data: {
            u: user
        },
        dataType: 'json' //xml, json, script, or html
        success:  function(data) {
            var pagenumber = //Your logic to get the parameter here;

            AJS.$('#container to hold the link').append('<a href="https://www.example.com/mypage.aspx?user=' + user + '&pagenumber=' + pagenumber  + '">Link Text</a>');
        },
        error:  function(x, y, z) {
            //Error handling code here.
        }, 
    });
});
</script>

0 votes
Michael Niu
February 27, 2014

Thank you very much!

0 votes
Michael Niu
February 27, 2014

Davin,

Thanks for the response, can you provide any sample code about this.

Thanks again

0 votes
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 27, 2014

You have a couple options. One would be to write your own plugin. If you don't want to go that far then you would to enable the html macro so that you can embed some Javascript. You can get the user using this Javascript method.

AJS.Meta.get('remote-user');

Confluence has jQuery installed, so you could use AJS.$.Ajax(); to get the parameters from an outside web service. Then you would just assemble the link with those parts.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events