- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 04:40 AM
Hi Everyone
I created a dashboard with a dynamic content block where I use a glide/jelly script to output data from ServiceNow.
The GlideObject has a static query to select the data from the database:
gr.addEncodedQuery('active=true^u_task_component.u_functional_area_name=0045_service^stateNOT IN6,3');
// gr.setLimit(300);
gr.query();
Now I need to make the query variables "u_functional_area_name" dynamic with either a text field or even better a dynamic option list with the functional areas directly from the database.
What I tried is to create a text field and send the value to the url using Javascript.
This is working but I can't fetch the parameter from the URL and pass it on to the GlideObject.
Does anyone have a solution for this?
The very best option would be to get the values from the Interactive Filter on the same dashboard and pass it on to the GlideObject.
Many thanks for your help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 07:02 AM
Ah I see. Yeah the widget in the dashboard is going to be within an iframe which is making it difficult to retrieve the parameters. But you mentioned that you are now getting the parameter and need to pass it to the g:evaluate.
How did you achieve getting the parameter? If you used client side methods, it will already be too late to pass to the g:evaluate unless maybe you use a two phase approach as g:evaluate happens server side.
Other methods I can think of are:
1) Instead of using g:evaluate use GlideAjax (client callable script include)
Here you would move your code in your g:evaluate into the client callable script include and use a GlideAjax script passing the parameter value to that and it returning the information you need.
2) Or you can move your code to a UI page and bring that into your widget with an iframe setting the src attribute with the page name and url parameters needed.
ie: <iframe src="uipagename.do?sysparm_myparam=myvalue" width="100%" height="400px"></iframe>
Of course your url would be built dynamically before putting it in the src attribute so that it gets the appropriate url parameter value
Since I already built the examples from my previous post with a UI page I put together the second option. Here is the dashboard output with a Dynamic content block
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 06:03 AM
since you said jelly can you share the complete script so that we can help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 06:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 08:22 AM
Hi @DBasualdo
In ServiceNow using Jelly usually a URL parameter can be retrieved by using the given RP class.
For example:
<p>${RP.getParameterValue('name_of_your_parameter')}</p>
If you prefix the parameter with sysparm_<your param> you can get away with doing this:
<p>${sysparm_myparm}</p>
<input value="${sysparm_myparm}" />
However, nowadays it also depends on how the page is rendered on how the parameter is applied to the url.
If the page with Jelly on it is navigated to without the ServiceNow framing:
https://<instance-name>.service-now.com/myuipage.do?sysparm_myparm=hello
This will work.
If viewing with the newest Experience url:
https://<instance-name>.service-now.com/now/nav/ui/classic/params/target/testpage.do?sysparm_myvar=hello
You'll find that it won't work. In order to make it work the url's parameters must be encoded like this:
https://<instance-name>.service-now.com/now/nav/ui/classic/params/target/testpage.do%3Fsysparm_myvar%3Dhello
Depending upon where you're using Jelly, script tags can be used as well to use plain Javascript:
The example below is a script using the given location object in JavaScript; using the search property to get the URL parameters and placing the parameter and its value in a div with id "search".
<div id="search" style="margin-top: 20px;"></div>
<script>
var loc = location.search;
var parms = JSON.stringify(loc).split("=");
search.innerHTML = parms[0].replace("?","").concat(" : ", parms[1])
</script>
Here is the example using a UI Page:
HTML/XML
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
${sysparm_myvar}
<p>${RP.getParameterValue('sysparm_myvar')}</p>
<div id="search" style="margin-top: 20px;"></div>
<script>
var loc = location.search;
var parms = JSON.stringify(loc).split("=");
search.innerHTML = parms[0].replace("?","").concat(" : ", parms[1])
</script>
</j:jelly>
Rendered page:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 06:28 AM
Thanks @ChrisBurks , I could manage to get my parameter from the URL.
Now I am still struggling to pass the parameter to Jelly. Is that even possible?