Common errors in UI Page / Macro
Let's admit it, Jelly is not very intuitive.
There are tons of documentation out there on Jelly. But I've got here a few pointers that is often missed while coding in a UI Page/Macro
1. Conditional statements:
The first thing that comes to mind while coding an AND condition is &&. But watch out.
- If you write a condition statement with && in jelly conditional tags (), it will not work.
Use &&... like this:
<j:if test="${jvar_variable1 == 'value1' && jvar_variable2 == 'value2'}">
Show this!
</j:if>
- Similarly, inside </strong> tags <strong>&&</strong> will not work.</p> <p>Use <strong>${AND} ...</strong> like this:</p> <pre><code><script> var a = 1; var b = 2; if(a=='1' ${AND} b=='2') alert('true'); else alert('false'); </script> </code></pre> <p>- In short, <strong>&</strong> cannot be used in the HTML area, use <strong>&</strong> instead.</p> <p><strong>2. getValue</strong></p> <p>When accessing a field value through a GlideRecord object, the common practice is obj.fieldValue. This doesn't return anything in Jelly.</p> <p>Always use getValue() or getDisplayValue(), like:</p> <pre><code><j:if test="${jvar_incObj.next()}"> ${jvar_incObj.getValue('short_description')} </j:if> </code></pre> <p><strong>3. Logging</strong></p> <p>Without logging, our developer life's would be tough. And without jelly logging, it would be miserable...</p> <p>gs.info only works for javascript variables(inside <g:evaluate>).</p> <p>To log a jelly value, use ${jellyVariableName}. For example:</p> <pre><code><j:set var="jvar_myJellyVariable" value="I love Jelly"/> ${jvar_myJellyVariable} </code></pre> <p><strong>4. Caching</strong></p> <p>UI Pages and Macros have caching issues.</p> <p>If you are using them on your forms through formatters, or dictionary attributes, you might see old data rendered until you clear your cache.</p> <p>I have encountered this many times, and was forced to replace <g:evaluate> scripts to GlideAjax-Script Include designs.</p> <p>If this article helped you, mark helpful.</p> <p>Also, feel free to share your learnings in the comments below</p> <p>Long Live ServiceNow!</p>
https://www.servicenow.com/community/now-platform-articles/common-errors-in-ui-page-macro/ta-p/2328387