How to set a variable value in jelly script and pass its value to javascript?

shipra
Giga Contributor

Hi All,

I have this code with me:

    <g:evaluate>

  var tab = new GlideRecord('u_cms_menu_table');

  tab.query();

      </g:evaluate>

    <j:while test="${tab.next()}">

  <j:if test="${tab.hasNext() == true}">

  <j:while test="${tab.next()}">

  ${j:set var="jvar_link" value="${tab.u_url.getDisplayValue()}"/>

  </j:while>

  </j:if>

  </j:while>

It is taking a columns value from a table which I have created now i want to store it in a variable and pass it to a JavaScript function. The column has URLs to different pages i intend to get th URL under Navigation menu.

Thanks in advance.

Shipra Shaw

8 REPLIES 8

andrew_lawlor
Giga Expert

If you're just pulling one field from each record, why not just throw them into an array and store it in a jelly variable?



<g:evaluate var="jvar_urls" object="true">


var urlArr = [];


  var tab = new GlideRecord('u_cms_menu_table');


  tab.query();


  while (tab.next())


urlArr.push(tab.u_url.getDisplayValue());



urlArr;


</g:evaluate>



Now, you can pass your array into a client-side function with the syntax: ${jvar_urls} You can then process the array in your JavaScript function.


Could you please explain what is the significance of var="jvar_urls" in the code you have provided. I dont need an array i just need to save one record and i want to use that record in another addQuery.



Thanks,


Shipra Shaw


jvar_urls is the name of the variable that will be set to the result of the script.


Hi Mujtaba, I dont need to pass it onto a script i just need to save it and use in an addQuery function. How to do that? Kindly help!! Thanks, Shipra Shaw