How to set a variable value in jelly script and pass its value to javascript?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2016 04:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2016 05:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2016 02:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2016 05:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2016 06:03 AM
Did you figure it out yet? 😃