Jelly and RP.getWindowsProperties

poyntzj
Kilo Sage

I am struggling to get a table name through to a ui page

The UI action has

dialog.setPreference("table_name", g_form.getTableName());

the ui page has

<g:ui_table>

  <g:set var="jvar_tablename" value="$[RP.getWindowProperties().get('table_name')]"/>

and a bit later on

gr.addQuery('table',jvar_tablename);

but it is not seemingly being passed the value

I have plenty of other ui pages that are working so I am a little bemused

for example, this is from one that works

UI action

dialog.setPreference("sysid", sysid);

UI Page

<g:ui_form>

<!-- Holds the Incident ID for use in HTML and the processing script -->

<j2:set var="jvar_incident_id" value="$[RP.getWindowProperties().get('sysid')]"/>

Only difference that I see is that the non working one is using a ui_table and the one that works is using ui_form, but I cannot see this making that much of a difference.

Any ideas would be appreciated

Cheers

1 ACCEPTED SOLUTION

This worked for me in the end



<g:evaluate jelly="true">


  var table_name = RP.getParameterValue('sysparm_table_name') + '';


  var strQuery = "table="+table_name+"^active=true"


  var templates = new GlideRecord('sys_template');


  templates.addEncodedQuery(strQuery);


  templates.orderBy('name');



Cheers


View solution in original post

21 REPLIES 21

Oh, I got excited then but no



I tried changing it to <g:evaluate> from g2


I tried object="true" on its own, jelly="true" on its own and combined.


sorry for the bad formatting, but trying to use the tags and it goes wrong



From this code on the UI page that loads I do see asdf + kb_knowledge


so the table name is passed - yippee


if I change the query to be addQuery('table','kb_knowledge');


I get the few test records I have in there so I know that is good



ARGGHH


Perhaps I need a weekend's rest from this bit - lol




<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<j2:set var="jvar_table_name" value="$[RP.getWindowProperties().get('sysparm_table_name')]"/>


<input type="hidden" name="table_name" value="$[jvar_table_name]"/>


asdf + $[jvar_table_name]


<TABLE BORDER="0" width="100%">


<TR>


<TD>


<b>Please select the template which you want to use.</b>


</TD>


</TR>


<tr><td>$[AMP]nbsp;   </td></tr>


<tr>


<td>


<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 no-right-padding">


<select name="template" id="template" onchange="selecttemplate()" class="form-control">


<g2:evaluate object="true" jelly="true">


var templates = new GlideRecord('sys_template');


templates.addQuery('table',jelly.jvar_table_name);


templates.orderBy('name');


templates.query();


</g2:evaluate>


<j:while test="${templates._next()}">


<option value="${templates.sys_id}">${templates.name}</option>


</j:while>


</select>


</div>


</td>


</tr>


Hi Julian,



Look at the following section:



1. You're mixing phases (calling a phase 2 var during phase 1)



2. Jelly (<j:>) doesn't see JavaScript variables (<g:>)




Try this instead:



<g2:evaluate var="jvar_templates" object="true" jelly="true">


var templates = new GlideRecord('sys_template');


templates.addQuery('table',jelly.jvar_table_name);


templates.orderBy('name');


templates.query();


templates;


</g2:evaluate>


<j2:while test="$[jvar_templates._next()]">


<option value="$[jvar_templates.sys_id]">$[jvar_templates.name]</option>


</j2:while>




Thanks,


-Brian


OK, let me go back a few steps as I may now have confused things with various updates


This version is the best I have that is working on the top dropdown is as follows.



The line that is disabled - gs.log('Jules :   + jelly.jvar_table_name)


If it is enabled, then that line does not appear in the log and i do not see any info


I have tried various combinations of g2 / j2 and I still do not get anywhere


I do occasionally see in the log "Jules : undefined"



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <j2:set var="jvar_table_name" value="$[RP.getWindowProperties().get('sysparm_table_name')]"/>


  <input type="hidden" name="table_name" value="$[jvar_table_name]"/>


  asdf + $[jvar_table_name]


  <TABLE BORDER="0" width="100%">


  <TR>


  <TD>


  <b>Please select the template which you want to use.</b>


  </TD>


  </TR>


  <tr><td>$[AMP]nbsp;   </td></tr>


  <tr>


  <td>


  <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 no-right-padding">


  <select name="template" id="template" onchange="selecttemplate()" class="form-control">


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


  gs.log('julian : ');


  //gs.log('jules : ' + jelly.jvar_table_name);


  var templates = new GlideRecord('sys_template');


  templates.addQuery('table','kb_knowledge');


  templates.orderBy('name');


  templates.query();


  </g:evaluate>


  <j:while test="${templates._next()}">


  <option value="${templates.sys_id}">${templates.name}</option>


  </j:while>


  </select>


  </div>


  </td>


  </tr>


  <tr><td>$[AMP]nbsp;   </td></tr>


  <tr><td>$[AMP]nbsp;   </td></tr>


  <tr><td>And then which fields you would like the template to overwrite</td></tr>


  <TR>


  <TD>


  <!-- Include the 'ui_slushbucket' UI macro -->


  <g:ui_slushbucket/>


  </TD>


  </TR>


  <TR>


  <TD align="right">


  <!-- Include the 'dialog_buttons_ok_cancel' UI macro -->


  <g:dialog_buttons_ok_cancel ok="return continueOK()" cancel="return continueCancel()" ok_type="button" cancel_type="button"/>


  </TD>


  </TR>


  </TABLE>


</j:jelly>



and shows me


find_real_file.png


Hi Julian,



There are a few issues...



First off, when you set a variable in phase 2:


<j2:set var="jvar_table_name" value="$[RP.getWindowProperties().get('sysparm_table_name')]"/>



You CANNOT use it in phase 1:


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


  gs.log('julian : ');


  //gs.log('jules : ' + jelly.jvar_table_name);



The way phases work on SNOW, phase 1 gets loaded and evaluated while ignoring anything that's phase 2... then it reloads and evaluates phase 2 with any results from phase 1 that you tell it to pass along.   You would either need to set your variable during phase 1, or move your <g:evaluate...> to phase 2.



Secondly...


With the <g:evaluate> tag...


  1. Whenever you use the tag "<g:evaluate...>", you MUST include the var="jvar_your_variable_name"... this is how it passes your evaluated value down the line to the rest of   your script.
  2. Whatever item is the last line of your <g:evaluate....> statement is what gets passed down as the value of "jvar_your_variable_name"


So, instead of:


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


  gs.log('julian : ');


  //gs.log('jules : ' + jelly.jvar_table_name);


  var templates = new GlideRecord('sys_template');


  templates.addQuery('table','kb_knowledge');


  templates.orderBy('name');


  templates.query();


  </g:evaluate>



You need to use:


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


      gs.log('julian : ');


      //gs.log('jules : ' + jelly.jvar_table_name);


      var templates = new GlideRecord('sys_template');


      templates.addQuery('table','kb_knowledge');


      templates.orderBy('name');


      templates.query();


      templates;


  </g:evaluate>




Next with your <j:...> tags, you need to refer to the values by these variable names.   Jelly doesn't know about the Javascript variables you declare within the <g> tags, only what you pass down to it.



So instead of:


  <j:while test="${templates._next()}">


  <option value="${templates.sys_id}">${templates.name}</option>


  </j:while>



Use:


  <j:while test="${jvar_templates._next()}">


  <option value="${jvar_templates.sys_id}">${jvar_templates.name}</option>


  </j:while>




Take a look through these articles on using Jelly tags and variables:


Jelly: Some Variables are More Equal than Others...


Jelly Tags - ServiceNow Wiki


Extensions to Jelly Syntax - ServiceNow Wiki




Thanks,


-Brian


I will try this a little later


While I was doing some more on this with the log statements last night I managed to get this page to take down our DEV instance, it went onto the other Node and I took that down too !



I'll look at the bottom part too which is from the SNC Guru - straight copy and paste which is why it is working off a group table ATM