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

I think I may have completely missed the boat on this exact ask.

 

Trying your suggestion for the client script does not work because as it turns out, I'm not including actual fields in the report but using getElement and getDisplayValue to output the data on the screen.

The report has something like this:

tahnalos_0-1677355779985.png

So what I am asking for is how can I figure out if caused_by is blank, how do I make sure the row is not included in the report?

Hi,

Yea, it seems so, because the title of your post is what I'm reply to. It seems you didn't describe what you're needing until close to now. My apologies if my replies haven't been helpful, but I've been trying to dig a bit more from you to fully understand what you're talking about. I've tried two replies now, sorry.


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

That should be easy: track down where incidentGr is initialized, where filters are applied to it and add one more:

incidentGr.addNotNullQuery('caused_by');

 

Not quite.  This report is to summarize a single record.  We print out this report as part of our weekly summaries for severe incidents.  We would require information on resolution if such notes are available but they don't want to see it if it is not filled in.

So what you want is to hide a column if no rows in that column contain a value?