Get paramter sysparm_query from URL using jelly

sergej11221
Mega Contributor

I want to get the sysparm_query value from this url: nav_to.do?uri=/ui_page.do%3Fsys_id%3D222a312fdbb9220065dfd001cf96191e%26sysparm_query%3Dstate%253D1

by using jelly. I used:

<j:set var="jvar_query" value="${sysparm_query}" />

and

<j:set var="jvar_query" value="${RP.getParameterValue('sysparm_query')}" />

In both cases I can't get the value.

14 REPLIES 14

Hi Chuck,


if i trigger the ui page from the header list - > the URL is following: ui_page.do?sys_id=222a312fdbb9220065dfd001cf96191e&sysparm_query=state%3D1.


I have access to the sys_id but sysparm_query stays always empty.



My Context Menu:



runContextAction();



function runContextAction() {


    var url = new GlideURL('ui_page.do?sys_id=222a312fdbb9220065dfd001cf96191e');


    url.addParam('sysparm_query', g_list.getQuery({orderby: true, fixed: true}));


    window.location = url.getURL();


}



This is working: I get the sys_id -> 222a312fdbb9220065dfd001cf96191e


<g:evaluate var="jvar_query" jelly="true" expression="RP.getParameterValue('sys_id')"/>


      <h1>${jvar_query}</h1>



Does not work: jvar_query stays empty:


<g:evaluate var="jvar_query" jelly="true" expression="RP.getParameterValue('sysparm_query')"/>


      <h1>${jvar_query}</h1>



Debug >>> JVAR: jvar_query=



I have created this client script to retrieve the sysparm_query value



function getSysparmQuery(variable) {


  var query = window.location.search.substring(1);


  var vars = query.split("&");


  for (var i=0;i<vars.length;i++) {


  var pair = vars[i].split("=");


  if (pair[0] == variable) {


  return decodeURIComponent(pair[1]);


  }


  }


}



How can I pass from the client script the variable to jelly?



This does not work:


<g:evaluate var="jvar_query" jelly="true" expression="getSysparmQuery('sysparm_query')"/>


Thank you for the information/update.



If you can get the sys_id, that suggests that the GlideURL line is working, and since you cannot get at the sysparm_query, that suggests that your url.addParam() is not working. I would look at constructing your URL another way. Have you tried it using a literal string?



e.g. window.location = 'ui_page.do?sys_id=sysparm_query=222a312fdbb9220065dfd001cf96191e&state%3D1';



From your UI context menu?


Thanks you for your suggestion but it does not work. I think I have the same problem with iFrame as mentioned in this disscussion: How to pass javascript variables into jelly tags?  



I have build a workaround. I store the sysparm_query in the session and use it for further calculation. But now I have a strange effect that I must call the context menu twice so that the query is stored in the session. Do you have any ideas why?


I solved the problem. I call the ui page direct from context menu like this:



runContextAction();



function runContextAction() {


    var url = new GlideURL('my_uipage.do');


    url.addParam('sysparm_query', g_list.getQuery({orderby: true, fixed: true}));


    window.location = url.getURL();


}



Now I can get the sysparm values with ${RP.getParameterValue('sysparm_query')}. Thank you for your help!


Aditya Mallik
ServiceNow Employee
ServiceNow Employee

Please use:



<g:evaluate var="jvar_query" jelly="true" expression="RP.getParameterValue('sysparm_query')"/>