GlideSysAttachment scoped doubt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 01:24 PM
I´m using GlideSysAttachment to transform a base64 in an attachment.
I was able to sucessfully add the image attachment in a ticket, but my real goal is to put it in a image field in the form.
This is possible

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 02:38 PM
Hi @User327722 ,
Yes, it is possible to display an image in a form field in ServiceNow, but there are certain steps and considerations when working with GlideSysAttachment to transform a base64-encoded image into an attachment and then display it in an image field.
Here’s a breakdown of how you can achieve this:
- Save the Base64 Image as an Attachment: First, you’ll need to save the base64-encoded image as an attachment on the record using GlideSysAttachment. You mentioned that this part is working fine for you, so I'm assuming you already have the base64 image saved as an attachment to a record.
Get the Attachment URL: After the image is saved as an attachment, you can retrieve the URL of the image from the attachment record using the GlideSysAttachment API. The URL will be used to reference the image in your form.
Here’s a code snippet that demonstrates how to retrieve the URL for the attachment:
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', <record_sys_id>); // Your record's sys_id
attachmentGR.query();
if (attachmentGR.next()) {
var attachmentUrl = new GlideSysAttachment().getAttachmentURL(attachmentGR);
gs.info('Attachment URL: ' + attachmentUrl);
}
Use a URL in the Image Field: Once you have the URL for the image, you can use that URL to display the image in an Image field on your form.
- If the Image field is a type of Image (field type: image), you can set the URL of the image dynamically by setting the field value to the URL of the attachment.
- If it’s a String field (field type: string), you can save the URL of the image and then use a widget or a custom script to display the image by dynamically embedding the image.
Example of Setting Image in the Form:
If you want to set the image dynamically in a script, here's an example:
var myRecord = new GlideRecord('incident');
myRecord.get(<incident_sys_id>); // Replace with your record's sys_id
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', myRecord.sys_id);
attachmentGR.query();
if (attachmentGR.next()) {
var attachmentUrl = new GlideSysAttachment().getAttachmentURL(attachmentGR);
myRecord.image_field = attachmentUrl; // Assuming image_field is the field that holds the image URL
myRecord.update();
}
- In the form, if the field is of type Image, it should display the image automatically if the field value is set to the URL of the attachment.
Considerations:
- File Type: Make sure the file type you're uploading is a valid image format (e.g., PNG, JPEG, GIF).
- Security: Make sure that the attachment is accessible publicly or to the correct user roles, as ServiceNow might restrict access based on permissions.
If my answer helped you, please mark it as the correct answer so that other users can find it and encourage us to continue responding to the community actively!
Thanks!
- Carlos Petrucio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 05:30 AM
Hi
In the real word for this process, it will begin with a user filling a catalog item form.
It is possible to do the attachment actions while in this fase or I will need to save the form, do the attchment actions and proceed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2025 05:41 AM
image field can only hold image whereas if you use field type of File attachment you can add whatever file type you wish
what's your business requirement?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader