- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2017 10:39 PM
I have two variables, one being set from syspam value and other from a query. I want to use them in a query based on if there is a value passed as parameter or if null use the value set in the g:evaluate.
This only works if syspam variable is populated. Using the test condition the value gets set but in the query it doesn't work. I tried to use "jvar_minc" insated of '${jvar_minc}' but this only works for one condition. How can I get this working. Is there a way to have if condition in g:evaluate?
<g:evaluate jelly="true">
<j:set var="jvar_inc" value="${RP.getParameterValue('sysparm_inc')}" />
</g:evaluate>
<g:evaluate jelly="true">
var currentval = new GlideRecord('u_temp'); .addEncodedQuery('u_start_date<=javascript:gs.daysAgoEnd(0)^u_end_date>=javascript:gs.daysAgoStart(0)');
currntval.query();
currentval.next();
var jvar_minc = currentval.q_val;
</g:evaluate>
<j:if test="${!empty(jvar_inc)}">
<j:set var="jvar_minc" value="${jvar_inc}" />
</j:if>
<g:evaluate jelly="true">
var inc = new GlideRecord('u_temp_table');
inc.addQuery('u_inc_name', '${jvar_minc}');
inc.addQuery('u_id', '${jvar_id}');
inc.query();
</g:evaluate>
when i print the values they come up right, its in the query it doesn't do the right evaluation.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 06:51 AM
Hi Sam,
You don't need a g:evaluate tag around the first j:set. g:evaluate is for running JavaScript. Also, when you use jelly="true", it says "I'm going to use a copy of the jelly variables", but you're not using them. Best practice is to avoid using ${variable} calls inside g:evaluate tags. You're half way there with jelly="true", but didn't use them. Finally, you had a hanging '.addEncodedQuery()" call with no object. Where did jvar_id come from? It is used in the second g:evaluate statement, but I don't see it set anywhere. Here's a cleaned up version of your script.
<j:set var="jvar_inc" value="${RP.getParameterValue('sysparm_inc')}" />
<g:evaluate var="jvar_minc" jelly="true">
var currentval = new GlideRecord('u_temp');
currentval.addEncodedQuery('u_start_date<=javascript:gs.daysAgoEnd(0)^u_end_date>=javascript:gs.daysAgoStart(0)');
currntval.query();
currentval.next();
currentval.q_val;
</g:evaluate>
<j:if test="${!empty(jvar_inc)}">
<j:set var="jvar_minc" value="${jvar_inc}" />
</j:if>
<g:evaluate jelly="true">
var inc = new GlideRecord('u_temp_table');
inc.addQuery('u_inc_name', jelly.var_minc);
inc.addQuery('u_id', jelly.jvar_id); // What is jvar_id???
inc.query();
</g:evaluate>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 06:51 AM
Hi Sam,
You don't need a g:evaluate tag around the first j:set. g:evaluate is for running JavaScript. Also, when you use jelly="true", it says "I'm going to use a copy of the jelly variables", but you're not using them. Best practice is to avoid using ${variable} calls inside g:evaluate tags. You're half way there with jelly="true", but didn't use them. Finally, you had a hanging '.addEncodedQuery()" call with no object. Where did jvar_id come from? It is used in the second g:evaluate statement, but I don't see it set anywhere. Here's a cleaned up version of your script.
<j:set var="jvar_inc" value="${RP.getParameterValue('sysparm_inc')}" />
<g:evaluate var="jvar_minc" jelly="true">
var currentval = new GlideRecord('u_temp');
currentval.addEncodedQuery('u_start_date<=javascript:gs.daysAgoEnd(0)^u_end_date>=javascript:gs.daysAgoStart(0)');
currntval.query();
currentval.next();
currentval.q_val;
</g:evaluate>
<j:if test="${!empty(jvar_inc)}">
<j:set var="jvar_minc" value="${jvar_inc}" />
</j:if>
<g:evaluate jelly="true">
var inc = new GlideRecord('u_temp_table');
inc.addQuery('u_inc_name', jelly.var_minc);
inc.addQuery('u_id', jelly.jvar_id); // What is jvar_id???
inc.query();
</g:evaluate>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 09:32 AM
Thanks a lot. Got it working with your suggestions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2019 12:45 PM
Chuck,
I know you're a super busy guy, but I feel like this is related in that I just don't know how to set/access the variable properly. If you have a minute can you give me some guidance on what I'm trying to do here?
I'm trying to pull in a value from my UI Action - stored via this code
dialog.setPreference('ei_sys_id', sys_id);
Into my UI Page - I have tried using multiple variations of g:evaluate an j:set to get the sys_id to use to query the table and build the array I need to print and nothing is working - but then again I am blindly stabbing in the dark, because I know very little about jelly.
Essentially what I want to is take that value from the UI action above and store it in a variable that would be referenced where <insertvariablehere> is in the snippet below.
<g:evaluate var="jvar_forecasts" object="true" jelly="true">
var arrForecasts = [];
var grForecasts = new GlideRecord("u_ehs_forecasts");
grForecasts.addEncodedQuery('u_forecast_parent=' + <insertvariablehere>)};
grForecasts.query();
Thanks,
Shannon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2019 07:05 AM
I found several examples of getPreference in UI pages. It appears to be accessed in JavaScript like this (from the catalog_find UI page...
<g:evaluate var="jvar_theme">
var theme = gs.getPreference('glide.css.theme.ui16');
if (null == theme){
var company = gs.getUser().getCompanyRecord();
if (null != company)
theme = company.getValue("theme");
}
theme;
</g:evaluate>