Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to pass javascript variables into jelly tags?

Community Alums
Not applicable

I am calling my UI Page within iFrame. When I try to do ${RP.getParameterValue('sys_id')}, it is not returning the sys_id of the incident record. I think its because the UI Page is within iFrame. So, with javascript I was able to get the part of the url (Incident sys_id). Now, I want to use this sys_id in my jelly to query the incident table and display all values.

example: https://something.something.com/ess/incident_created.do?sys_id=13ecc01637915e0006c11f9543990e0a

<script>

  var cmshelp_url = top.location.href;

  var help_sysid = cmshelp_url.substr(cmshelp_url.length-32);

</script>

<j:set var="jvar_inc" value="${help_sysid}" />   // THIS IS NOT WORKING. ANY SUGGESTIONS?

<g:evaluate jelly="true">

      var inc = new GlideRecord('incident');

      inc.addQuery('sys_id', jelly.jvar_inc);

      inc.query();

</g:evaluate>

1 ACCEPTED SOLUTION

Manjul Katare
ServiceNow Employee
ServiceNow Employee

Try this out Rajinis !!!!


It would definitely work as I have used it before on CMS:




Pass value from URL To UI Page / Macro /   Record Producer



#1: Using: JS



Assume iFrame URL has :   &req_type=SOMETHING



UI page can have a script like:


function onLoad() {


    var url = window.location.toString();


  var parms = url.toQueryParams();


  if (parms["req_type"] == "SOMETHING") {


  /* do something here   */


  }


}




OR




#2 Using: Jelly


Assume iFrame URL has :   &pointer_name=counter



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


<j:if test="${jvar_pointer == 'counter'}">


      <p>Hello World! - ${jvar_pointer}</p>


      /* do something here   */


</j:if>



Hope this help!


-Manjul


View solution in original post

9 REPLIES 9

srinivasthelu
Tera Guru

Hi rajinis,



Can you please change your parameter name and try?



https://something.something.com/ess/incident_created.do?syparm_sys_id=13ecc01637915e0006c11f9543990e...



UI Page code should be



<g:evaluate jelly="true">


      gs.log("incident_created${sysparm_sysid}");


      var inc = new GlideRecord('incident');


      inc.addQuery('sys_id', '${syparm_sys_id}');


      inc.query();


</g:evaluate>


Community Alums
Not applicable

Sorry. Not working


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Rajinis,



In addition, you may find the below thread helpful.


Passing Javascript variables into Jelly Tags.


Mike Allen
Mega Sage

I just do this:



<g:evaluate jelly="true">


      var inc = new GlideRecord('incident');


      inc.addQuery('sys_id', "${help_sysid}");


      inc.query();


</g:evaluate>