Get Display Value Using Variable for Field Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 08:39 AM
So, I have a UI Page with the code below in the HTML box and I want to get the Display Value of the 'channel' variable from the 'oo_line_item' GlideRecord.
Rather than writing a 'getDisplayValue' for every case, I'm trying to condense the code so that the field I'm trying to get the display value for is determined dynamically.
I can see that I'm getting the correct value assigned to the 'channel' variable. But this line isn't working: oo_line_item.channel.getDisplayValue();
Is it possible to run the getDisplayValue() method on a dynamic field value?
${ var site = 'site_oo_' }
<j:choose>
<j:when test="${ oo_line_item.property.getDisplayValue() == 'Austin' }">
${ var market = 'austin'; }
</j:when>
<j:when test="${ oo_line_item.property.getDisplayValue() == 'Charlotte' }">
${ var market = 'charlotte'; }
</j:when>
<j:when test="${ oo_line_item.property.getDisplayValue() == 'Dayton' }">
${ var market = 'dayton'; }
</j:when>
</j:choose>
${ var channel = site.concat(market); }
${ var channel_display = oo_line_item.channel.getDisplayValue(); }
<div class="oo-site-channel">
${ channel_display }
</div>
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 08:44 AM
Hi Ryan,
Aren't all fields dynamic values? 🙂
Since you just declared channel, it's not going to have a getDisplayValue() method. That's something that comes along with many of the ServiceNow objects & properties. Not knowing what site and market are, perhaps you could use
${var channel = site.concat(market.getDisplayValue()); }
also, take a look at the Switch statement in Jelly instead of lots of if or when statements... The first the videos in this playlist might help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:37 AM
Mr. Tomasi!
I'm honored to be talking to you. Love the YouTube series! Still new to ServiceNow and Jelly. I'll work on restructuring this logic into a switch statement.
I tried that suggestion but it didn't work. Basically, the 'property' variable determines which channel field displays on the form. So, in this example, it might be:
site_oo_austin
site_oo_charlotte
site_oo_dayton
So, for Austin, I would want:
<div class="oo-site-channel">
${ oo_line_item.site_oo_austin.getDisplayValue(); }
</div>
I could put those divs into each <j:when> like so:
<j:when test="${ oo_line_item.property.getDisplayValue() == 'Austin' }">
<div class="oo-site-channel">
${ oo_line_item.site_oo_austin.getDisplayValue(); }
</div>
</j:when>
But it seems like that would produce a bunch of redundant code - which I'm trying to avoid.
To simplify, should something like this work?
<j:when test="${ oo_line_item.property.getDisplayValue() == 'Austin' }">
${ var VARIABLE = 'site_oo_austin'; }
</j:when>
${ oo_line_item.VARIABLE.getDisplayValue(); }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:41 AM
Step 1: Get it working with the 'static' solution. As you learn, new methods may appear that let you do this dynamically and reduce repeating code. At this point I don't have a solution.
Thank you for the kind words! Glad you enjoy the videos.