- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2015 10:15 PM
Hi Everyone,
I have a bit of a problem with passing variables in the evaluate tag. Below is the script:
<g:evaluate var="jvar_gr" object="true">
var gr = new GlideRecord('xxxx_database_view');
gr.query();
gr;
</g:evaluate>
<j:if test="${jvar_gr.hasNext()}">
<j:while test="${jvar_gr.next()}">
<tr>
<td>${jvar_gr.getValue('xxx_employee')}</td>
<td>${jvar_gr.getValue('xxx_dateinput')}</td>
<td>${jvar_gr.getValue('xxx_hours')}</td>
<td>${jvar_gr.getValue('xxx_activity')}</td>
<td>${jvar_gr.getValue('xxx_description')}</td>
<td>${jvar_gr.getValue('yyy_team')}</td>
</tr>
</j:while>
</j:if>
If I don't use the var="jvar_gr" in the evaluate tag and just continue on with the glide record script that I usually use, it works. Its returning the records that I want to return.
I tried adding an alert script after line 6 and the alert script is working. But when I tried putting the alert script between line 7 and 8, the alert script isn't working and I'm guessing that there's something wrong with the variable jvar_gr. Can someone tell me what's wrong with my code?
My reference: Jelly Tags - ServiceNow Wiki
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2015 11:07 PM
Hi Jan,
Sure, no problem.
The variable you set to store the new gliderecord, is the name you should set in the g:evaluate tag. In your case your set the var as gr; it's recommended to use something logical, like I did with the table name, to avoid confusion.
I would write your code like the following:
<g:evaluate var="incident" object="true">
var incident = new GlideRecord("incident"); // mark this the same name as your g_evaluate variable name
incident.addQuery("active", "true");
incident.query();
incident; // this is the variable put into the variable jvar_gr
</g:evaluate>
The jvar prefix, is in the wiki; but I believe that's for back-end queries, rather than front-end. I suspect it doesn't always mix well. I have never had it work, tbf. The way I described is how it always works for me. Not declaring the variable can and will lead to some odd results, so I do recommend declaring it.
I keep hitting submit, before I'm ready to answer fully, apologies. Its 2am here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2015 11:24 PM
Thank you for your time. I appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2015 11:29 PM
You're welcome! Glad to help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 07:50 PM
If this solved your issue, can you please mark this as helpful/answered? Thanks!