- 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
‎07-01-2019 05:03 AM
Yes, I am able to get the value from getPreferences if all I want to do is store it in a variable and return that variable. The issue I'm having is that i want to create an array, use the variable to build the array and then return the array. It's that setting inside of a bigger setting that is causing the issues.
Thanks,
Shannon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 05:21 AM
Can you share the code where you are getting the value and trying to build the array? It's a bit tough to advise without context. Note, if the script is 100s of lines long, you can just post the important bits.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 05:51 AM
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 to use to query the table and build the array I need to print. I want to take the value from the UI action 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();
I can get the value into a variable using code like yours, but then if I try to use that variable in the bit of code above (which would be a separate g:evaluate) then it tells me it's undefined. I guess you can't pull from one g:evaluate to another? But then I tried setting it using a j:set and that wasn't working either. I have literally tried dozens of ways to try to essentially use 2 variables in the same set of code where I just need to return that array, but can't figure out the right way to do it.
Thanks,
Shannon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 05:59 AM
Do you get any log output when you save the variable and output it? Example:
<g:evaluate>
var id = gs.getPreference('ei_sys_id');
gs.print('id=' + id);
</g:evaluate>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2019 08:38 AM
Using that code, I get 'null' as the value
Using this code I had tried before
<g:evaluate var="jvar_sys_id"
expression="RP.getWindowProperties().get('ei_sys_id')" />
I can print the value later outside the g:evaluate
But using that code I don't know how to print from within it, or access the value from another g:evaluate.
Thanks,
Shannon