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

Miriam Berg
Kilo Guru

Hi there,



To save a variable in jelly, use the tag that you yourself provided on line 8: Jelly Tags - Set


You saved a value into the variable called 'jvar_link":



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



To use this variable again later, you could use an evaluate tag as described on the wiki: "If you would like to access Jelly variables inside an evaluate, include jelly="true" in the evaluate and add "jelly." before the Jelly variable's name. Extensions to Jelly Syntax



<g2:evaluate var="jvar_page" jelly="true">


...


<!-- to access your variable using javascript: jelly.jvar_type -->


...


</g2:evaluate>



If this doesn't answer your question, could you explain more clearly where you want to use the saved variable?



Best Regards,


Miriam


Hi Miriam, Basically, i am trying to save data from a reference field of a table in a variable in dynamic block. How do I set variable type as reference in jelly code? Thanks in advance. Shipra Shaw


Hi again,



If you want to use a reference variable, set the object attribute to "true" and get the reference as below:



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


        var gr = new GlideRecord("u_cms_menu_table");


        gr.get(SYS_ID_HERE);


        gr;


</g:evaluate>



Then reference the jelly variable "jvar_menu" and its properties for example like this:



${jvar_menu.getDisplayValue('number')}



Hope this helps!


BR /Miriam


Miriam Berg
Kilo Guru

Did you figure it out yet? 😃