Showing image from an Image field in a Jelly page

andersba
Giga Contributor

I have a table with some text fields and an Image field. On my Jelly page, I can pull records from my table and show the text columns just fine - ${gr.u_name} and the like. I cannot for the life of me figure out how to display the image field. ${gr.u_image} just shows up as nothing. I've also tried combinations like and ${gr.u_image.url} and pretty much anything else I can think of. How do I show my u_image field's image?

5 REPLIES 5

gaidem
ServiceNow Employee
ServiceNow Employee

It's really hard to help without having the full picture. Post your entire XML.


DrewW
Mega Sage
Mega Sage

What you need to do is query the sys_attachment table for the sys_id of the image.

Fields to query on
table_name = table of the URL field.
file_name = name of the URL field.
table_sys_id = the sys_id of the record in the table that has the URL field you are trying to get the image for.

Then your link will look like this


This is the only way I know of to do it, so if someone has a better/faster way I would like to know.


andersba
Giga Contributor

Thanks, Drew, that worked great.


CapaJC
ServiceNow Employee
ServiceNow Employee

The following in a UI Page will show Beth Anglin's user photo:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_usr_image">
var gr = new GlideRecord('sys_user');
gr.get('user_name', 'beth.anglin');
gr.photo.getHTMLValue();
</g:evaluate>

<g:no_escape>${jvar_usr_image}</g:no_escape>
</j:jelly>


Hope that points you in a useful direction!