- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 10:04 PM
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
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 10:58 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 10:31 PM
Hi Shahid,
Is your link script present in client side or server side. If on server side then you can following
var url = gs.getProperty('instance_name') + '.service-now.com';
If you want your dynamic url in client side then you will have to use g:evaluate tag to set this variable and get it using jelly tag as below
Mark my reply as Correct and also hit Like and Helpful if you find my response worthy.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 10:43 PM
Hi Ankur,
My script looks like as below:-
___
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<p><b><font size ="4">To view the list, please click <a href="https://" +gs.getProperty('instance_name')+ ".service-now.com/u_c_party_list.do?sysparm_query=sys_class_name%3Du_c_party%5Esys_created_onONYesterday%40javascript%3Ags.daysAgoStart(1)%40javascript%3Ags.daysAgoEnd(1)%5Eu_nameISEMPTY" target="_blank"><font color="blue"> here.</font></a></font></b>
</p>
</g:ui_form>
</j:jelly>
______
In the href tag i am fetching the system property and concatenating it with the rest of the URL.
instance_name system property stores the name of the current URL in all the instances.
Can you let me know how can i use the system property in the UI Page script thus making the link dynamic to respective instances?
Thanks,
Shahid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 11:08 PM
Hi Shahid,
Following is the updated code
<g:evaluate var="jvar_urlLink" jelly="true">
var url = gs.getProperty('instance_name') + '.service-now.com/u_c_party_list.do?sysparm_query=sys_class_name%3Du_c_party%5Esys_created_onONYesterday%40javascript%3Ags.daysAgoStart(1)%40javascript%3Ags.daysAgoEnd(1)%5Eu_nameISEMPTY' ;
url;
</g:evaluate>
<p><b><font size ="4">To view the list, please click <a href="${jvar_urlLink}">Link
</a></font></b>
</p>
The dynamic url will be stored in the variable "jvar_urlLink" and it will fetch the url based on the instance
Mark my reply as Correct and also hit Like and Helpful if you find my response worthy.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2021 07:29 PM
Thanks Ankur, and Shahid for the original post. Solved my question without even needing to ask 😃