
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2023 10:05 PM - edited ‎11-09-2023 11:39 PM
Hi All,
I have an requirement where for a particular RITM I need to fetch the variable values along with the attachment added to that RITM.
I am able to fetch RITM variable by following below way:
- Namespace: now
- API Name: Table API
- API Version: Latest
- Retrieve records from a table (GET)
- tableName: sc_req_item
- sysparm_query: number=RITM0000001^active=true
- sysparm_display_value: true
- sysparm_fields: number,assignment_group,variables.variableA,variables.variableB
On following above way I am getting the value, but I also want to fetch the attachment in the RITM (not the name the file).
I am very new to integration, so I am looking if someone can guide me step by step process on the same.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2023 11:41 PM
As it for the same system ,thus, I created a Scripted REST API and it worked:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Get RITM number from the request parameters
var ritmNumber = request.queryParams.number;
// Fetch RITM variables
var ritmRecord = new GlideRecord('sc_req_item');
ritmRecord.addQuery('number', ritmNumber);
ritmRecord.query();
if (ritmRecord.next()) {
// Fetch variables
var variables = {
variableA: ritmRecord.variables.variableA,
variableB: ritmRecord.variables.variableB
// Add other variables as needed
};
// Fetch attachments
var attachments = [];
var attachmentRecord = new GlideRecord('sys_attachment');
attachmentRecord.addQuery('table_sys_id', ritmRecord.sys_id.toString());
attachmentRecord.query();
while (attachmentRecord.next()) {
//var attachmentLink = gs.getProperty('glide.servlet.uri') + attachmentRecord.sys_id;
var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentRecord.sys_id;
attachments.push({
file_name: attachmentRecord.file_name.toString(),
attachment_link: attachmentLink
// Add other attachment details as needed
});
}
// Prepare response
var result = {
ritm_number: ritmRecord.number,
assignment_group: ritmRecord.assignment_group.getDisplayValue(),
variables: variables,
attachments: attachments
};
// Send the response
response.setBody(result);
} else {
// RITM not found
response.setError(404, 'RITM not found');
}
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2023 11:19 PM
who will be consuming the endpoint? an external system?
to get attachment data you need to use Attachment API as attachments are stored in sys_attachment table. Use the RITM sysId to query in the Attachment API
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2023 11:41 PM
As it for the same system ,thus, I created a Scripted REST API and it worked:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Get RITM number from the request parameters
var ritmNumber = request.queryParams.number;
// Fetch RITM variables
var ritmRecord = new GlideRecord('sc_req_item');
ritmRecord.addQuery('number', ritmNumber);
ritmRecord.query();
if (ritmRecord.next()) {
// Fetch variables
var variables = {
variableA: ritmRecord.variables.variableA,
variableB: ritmRecord.variables.variableB
// Add other variables as needed
};
// Fetch attachments
var attachments = [];
var attachmentRecord = new GlideRecord('sys_attachment');
attachmentRecord.addQuery('table_sys_id', ritmRecord.sys_id.toString());
attachmentRecord.query();
while (attachmentRecord.next()) {
//var attachmentLink = gs.getProperty('glide.servlet.uri') + attachmentRecord.sys_id;
var attachmentLink = gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + attachmentRecord.sys_id;
attachments.push({
file_name: attachmentRecord.file_name.toString(),
attachment_link: attachmentLink
// Add other attachment details as needed
});
}
// Prepare response
var result = {
ritm_number: ritmRecord.number,
assignment_group: ritmRecord.assignment_group.getDisplayValue(),
variables: variables,
attachments: attachments
};
// Send the response
response.setBody(result);
} else {
// RITM not found
response.setError(404, 'RITM not found');
}
})(request, response);