- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 11:14 AM - edited 03-11-2023 11:14 AM
Hi,
I was wondering if it is possible to retrieve the sys_id of the file name of an attachment record and not the sys_id of the record.
Like when you right-click on it but from a script ?
I need to get it dynamically.
Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 02:27 PM
Hi,
You can find it using gliderecord api on sys_attachment table.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 02:27 PM
Hi,
You can find it using gliderecord api on sys_attachment table.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 09:55 PM
Yes, it is possible to retrieve the sys_id of an attachment file name in ServiceNow using scripting. You can use the GlideRecord API to query the sys_attachment table and retrieve the sys_id of the attachment based on the file name.
// Define the file name of the attachment
var fileName = "example.txt";
// Query the sys_attachment table to retrieve the sys_id of the attachment
var gr = new GlideRecord('sys_attachment');
gr.addQuery('file_name', fileName);
gr.query();
if (gr.next()) {
var sysId = gr.getValue('sys_id');
gs.info("Attachment sys_id for file " + fileName + " is " + sysId);
} else {
gs.warn("No attachment found with file name " + fileName);
}
In this example, we define the file name of the attachment we want to retrieve the sys_id for. We then create a new GlideRecord object for the sys_attachment table and add a query to find the record with a matching file name. We then execute the query and check if any records were returned. If a record is found, we retrieve the sys_id field value and log it to the console. If no records are found, we log a warning message.