- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 02:57 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2014 02:24 AM
This piece of code seems to work fine on a demo instance:
<g:evaluate var="jvar_site_and_page" jelly="true">
var page = new GlideRecord('content_page');
page.get('${RP.getParameterValue('sysparm_sys_id')}');
page.content_site.url_suffix + '/' + page.url_suffix;
</g:evaluate>
Current URL is this:<br/>
${RP.getParameterValue('jvar_base_uri')}${jvar_site_and_page}.do
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2014 01:50 AM
That's because getReferringURL() returns the link from which you came to the current page, not the URL of the current page itself.
Why do you need to get the full URL? You know the name of the page you are working on. So you can use it in the code without reading the URL. It is usually parameters that need to be retrieved dynamically because you never know their values beforehand. And to access parameters you can use the following methods:
RP.getParameterValue(parameterName)
RP.getParameters()
In fact, I think you should be able to get the URL of the current page as follows:
RP.getParameterValue('sysparm_this_url')
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2014 02:04 AM
Tested in a demo instance and unfortunately it does not seem to work in content pages.
But you can still get the sys_id of your content page using RP.getParameterValue('sysparm_sys_id') and then query Pages [content_page] table to get the URL suffix of the page and the corresponding content site.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2014 02:24 AM
This piece of code seems to work fine on a demo instance:
<g:evaluate var="jvar_site_and_page" jelly="true">
var page = new GlideRecord('content_page');
page.get('${RP.getParameterValue('sysparm_sys_id')}');
page.content_site.url_suffix + '/' + page.url_suffix;
</g:evaluate>
Current URL is this:<br/>
${RP.getParameterValue('jvar_base_uri')}${jvar_site_and_page}.do
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2014 03:56 AM
Hi Brad and Slava, Thank you for your kind support. It was a great assistance and I am able to build my solution.
Brgds, AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2015 10:08 AM
I know this is a while ago (and that this might be considered picky!), but best practice is to use the 'jelly' variable when doing this, and not to use JEXL expressions inside an evaluate.
You've already done 'jelly=true' when initializing the g:evalauate tag, so you have access to your parameter with the following:
jelly.RP.getParameterValue('sysparm_sys_id');