Jelly Script: how to hide an empty field on a UI Page

tahnalos
Kilo Sage

I have a UI page that generates a report referring to the Incident table.  This UI Page is supposed to summarize several fields in the incident form but at any given time, these fields may not necessarily be filled in.  The ask is that if the field does not have a value, it needs to be removed from the report.  This report is built via HTML so I assume that Jelly scripting will be required, wondering if anyone can provide the basics on how that would work.

 

Thanks

1 ACCEPTED SOLUTION

raphaelcrv
Kilo Guru

Could u share more details a snippet of the code and explain what you need to do ? 

So follow some example to hide an empty field on a UI Page using Jelly Script, you can use the <j:if> tag along with the <j:out> tag to conditionally display the field only if it has a value. Here's an example:

 

<j:if test="${empty myField}">
   <!-- myField is empty, so do not display it -->
   <j:out value=""/>
</j:if>
<j:if test="${not empty myField}">
   <!-- myField has a value, so display it -->
   <j:out value="${myField}"/>
</j:if>

 

 

In the example above, replace myField with the name of the field you want to conditionally hide based on its value.

The <j:out> tag is used to output the value of a variable or expression, and setting its value to an empty string "" effectively hides the field from the UI.

The first <j:if> block checks if the myField variable is empty, and if it is, it outputs an empty string. The second <j:if> block checks if the myField variable is not empty, and if it is not, it outputs the value of the myField variable.

Note that this example assumes that myField is a variable that has been defined somewhere in your Jelly Script code. If myField is a field on a record in ServiceNow, you will need to use the appropriate GlideRecord API to retrieve its value.

 

Please mark reply as Helpful/Accept Solution, if applicable. Thanks!
If my response was helpful and/or provided a solution, please consider marking it as such. Thank you!

View solution in original post

12 REPLIES 12

Allen Andreas
Administrator
Administrator

Hi,

Do you mean the "report" is not using the out of box reporting feature, but instead, it's using a UI Page or something to that effect? Can you give a bit more info as to your setup?

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Yes, sorry, it's a UI page but set up as a report using HTML.  An export function is used to export to PDF.

So yes, I'm trying to use Jelly to adjust for the report, so wondering what I need to do for that.

Bump

Hello,

If my original reply was Helpful to prompt you to add more information to your post, which you've then edited, which could help others know more...to help you...please mark it as Helpful.

 

In any case, you can use this in client script, for example, to hide a field as needed if it's empty:

 

gel('field_name').style.display = 'none';

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!