UI page - HTML section - difference between <g> and <g2>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2011 02:51 AM
Hi,
Just trying to understand the difference between
and
<g>
<g2>
In a UI page - HTML section I have the following :
// This is treated as code and returns the results
<g:evaluate var="mynames" jelly="true">
var gr= new GlideRecord('u_platfs');
gr.query();
</g:evaluate>
// This returns the contents as as a string: (Only difference is the <g> is changed to <g2>
<g2:evaluate var="mynames" jelly="true">
var gr= new GlideRecord('u_platfs');
gr.query();
</g2:evaluate>
e.g. var gr= new GlideRecord('u_platfs'); gr.query();
I know that the difference between
and
<g>
is that
<g2>
is cached but no idea why this should have an impact.
<g>
So why is
returning the contents as a string?
<g2>
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2011 06:59 AM
Can you post the full contents of the UI page along with a screenshot of the output of both code variations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2011 05:21 AM
The order of execution is:
- g sections are evaluated. Output is cached.
Use ${} to evaluate expressions in the HTML portion. Use this if it's a value that is going to be constant on each page display. Using this when you should use g2 will mean that values related to the record (or whatever else is varying) won't change as you load the page.
- g2 sections are evaluated, output is sent to client (browser, etc.)
Use $[] to evaluate expressions in the HTML portion. Use this if it's a value that is going to change on each page display, using this when you don't need to will make the display of the page slower.
I think what's wrong is that you're not actually returning a string in your evaluate block, so Jelly is giving you some debug output. Also, as it stands, the value being assigned is the result of the gr.query() method, which is probably not what you want. (I'm not even sure why it might work in the first case, and you don't say what value you get.)
I think you also need to prefix the variable names you use with 'jvar_', if you want to be able to access them with ${} or $[]
// This is treated as code and returns the results
<g:evaluate var="jvar_mynames" jelly="true">
var gr= new GlideRecord('u_platfs');
gr.query();
gr.next();
gr.sys_id;
</g:evaluate>
output phase 1:
${jvar_mynames}
<g2:evaluate var="jvar_mynames" jelly="true">
var gr= new GlideRecord('u_platfs');
gr.query();
gr.next();
gr.sys_id;
</g2:evaluate>
output phase 2:
$[jvar_mynames]
(Hopefully the forum hasn't eaten any critical characters in that code segment.)
Alternatively, you can construct evaluate in either phase as follows:
<g:evaluate>
var gr= new GlideRecord('u_platfs');
gr.query();
</g:evaluate>
<j:while test="${gr.next()}">
<h1>${gr.sys_id}</h1>
</j:while>
<g2:evaluate>
var gr= new GlideRecord('u_platfs');
gr.query();
</g2:evaluate>
<j2:while test="$[gr.next()]">
<h1>$[gr.sys_id]</h1>
</j2:while>
Hopefully that helps.