How to access a custom URL parameter and use it in a GlideObject or Jelly

DBasualdo
Tera Contributor

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!

1 ACCEPTED SOLUTION

@DBasualdo,

 

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

dynamic_content_block_dashboard.png

View solution in original post

7 REPLIES 7

Hi @DBasualdo ,

You already have half of the setup by adding the "jelly=true" attribute. The second half is to call jelly dot-walked to the variable name. From my example that I posted it would be something like:

jelly.sysparm_myvar;

So in context if I were using that within a g:evaluate:

 

<!--Phase 1 depending -->
<g:evaluate jelly="true" object="true" >
  var doJelly = jelly.sysparm_myvar";
  ....
</g:evaluate>

<!-- Phase 2 depending -->
<g2:evaluate jelly="true" object="true">
  var doJelly = jelly.sysparm_myvar";
  ...
</g2:evaluate>

 

 

It also depends on what you mean by "pass the parameter to Jelly". In the example I posted, it is already "in jelly".

With the g:evaluate, you're stepping out of Jelly and into JavaScript.  The attribute "jelly=true" means to allow the script to use jelly variables.

If you want to pass variable values directly to JavaScript outside of a g:evaluate then use hidden input elements similar to the following.

 

<input id="paramVal" name="paramVal" type="hidden" value="${RP.getParameterValue('sysparm_myvar')}" />

 

 

Then you can use regular JavaScript to get the value. Most of the UI Pages have plenty of examples out-of-box.

DBasualdo
Tera Contributor

@ChrisBurks  thanks for your response.

What I mean is that I need to get the URL parameter highlighted below and pass them to the glideQuery.

 

<g:evaluate jelly="true" object="true" var="jvar_test">

  // CREATE NEW GLIDE OBJECT WITH CASES
  var gr = new GlideRecord('cases');
  gr.addEncodedQuery('active=true^u_task_component.u_functional_area_name=0045_service^stateNOT IN6,3');
</g:evaluate>

 

Dashboard URL: https://DOMAIN/now/nav/ui/classic/params/target/%24pa_dashboard.do%3Fsysparm_dashboard%3Db9e6e8b8c31...sysparm_farea%3D004_c4c%26sysparm_exarea%3D%26sysparm_cp%3D

 

RP.getParameterValue is not working within this Dynamic Content Widget.

 

I also tried the recommended scripts from this thread but this is also not working:
https://www.servicenow.com/community/developer-forum/jelly-script-get-parameter-from-url/m-p/1707232...

Is it not working because this script is used within a dynamic content block on a dashboard?

@DBasualdo,

 

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

dynamic_content_block_dashboard.png