How to access a URL inside g:evaluate tag in Jelly

antonymirza
Tera Expert

Developing a new site using ServiceNow CMS and need to access the URL value inside jelly code. I see that window.location method does not work inside j or g tag in jelly instead in script tag.

 

Can someone please explain how to access URL value inside jelly tags?

Slava Savitsky
Giga Sage

This Wiki article explains how to read URL parameters in a UI Page:


UI Pages - ServiceNow Wiki


Is this what you are looking for?


Hi Slava, I have not used a UI page yet and proceeding with dynamic pages. And, in a dynamic page, if I use window.location within script tag I am able to access the URL but cannot pass it to a Jelly variable.


Therefore, as an alternate I started checking if I can access the URL in a similar way within jelly tags but that does not work. Once, I am able to get the URL value within jelly tags, then I will proceed with split.


Brgds, AM


You can use the RP object to return the url as detailed in this kb article:


http://wiki.servicenow.com/index.php?title=Extensions_to_Jelly_Syntax#RP



${RP.getReferringURL()} would return the url that got you to the page.


Hello Brad,



Thank you for showing your interest. I tried using the option you suggested but I come up with "view_content.do" instead of actual URL value.



Let me explain what I did and what I am expecting.



1. I have created a sample site using CMS named as "windowshopping" with a URL suffix as "shop".


2. Created a page as "main page" with URL suffix "main" and set it as the homepage of this site.


3. Created a dynamic block wherein I use below code in g:evaluate for accessing the URL and linked with "main page".



====================


var gr = "${jvar_RP.getReferringURL()}";


====================



Therefore, now whenever I access https://sandbox.service-now.com/shop, I want this URL value in my variable "gr" but it stores "view_content.do".



Please check if you can assist further.



Brgds, AM