Set the instance name dynamically in the UI Page script

shahid1
Kilo Expert

Hi All,

I have designed a small UI Page and the script in it contains a link , clicking on it will take the user to a specific page.

I have hard coded the URL in the script within the HREF tag. But i want this link to be dynamic.

For example:- If this link is clicked in the test instance then the expected page which should open should be of test instance and so on for other instances respectively.

Any help here?

Thanks,

Shahid

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Hi Shahid,



You can do it in server sided without creating any property or server side calls.


I am providing you an example of ui page.



HTML of the UI page:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<a href="javascript:showLink()" >Dynamic link</a>


</j:jelly>






Client script of the UI page:



function showLink()


{


var url = window.location.href;


  var str = url.split(".")[0];


  window.open(str+'.service-now.com');


}






Thanks,


Mihir


View solution in original post

7 REPLIES 7

prithvirajchaud
Mega Expert

well you can put the link like this.


<a href="/<link of your page>">Link</a>



or if you really need the url of the current instance you can use this



gs.getProperty('glide.servlet.uri')


This will give you an output like https://<your-instance-name>.service-now.com/


Hi Prithviaj,



I have used this in my client side and server side scripts but i dont have much knowledge about jelly scripting.



Please have a look at my reply to Ankur and let me know if you can help.



Thanks and RGDS,


Shahid


Mihir Mohanta
Kilo Sage

Hi Shahid,



You can do it in server sided without creating any property or server side calls.


I am providing you an example of ui page.



HTML of the UI page:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<a href="javascript:showLink()" >Dynamic link</a>


</j:jelly>






Client script of the UI page:



function showLink()


{


var url = window.location.href;


  var str = url.split(".")[0];


  window.open(str+'.service-now.com');


}






Thanks,


Mihir