- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2024 05:51 AM
Hello.
I have a Record Producer that is set to kick off an Incident in some situations and a Request in other situations, depending on the value of a variable.
That part of the process (i.e. kick off Incident or Request) is working as expected.
My issue is that if there is an attachment and it is kicking off a Request then the attachment does not get added to the Request (in sys_attachments table it shows the attachment being associated with the Incident table).
Anyone have any ideas on how I can set it so that if a Request is being kicked off that the attachment comes with it?
Thank you!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 06:05 AM
Hi Tom, Sorry I didn't realise you replied.
From your shared script there are a few issues.
- When creating request management records, I'd really push to using the CartJS API as to create records how SN intends CartJS | ServiceNow Developers
- Attachments are transient before they're set to their final record destination.
You can use the following, after you have the newly redirected target record defined, to move the attachments
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments(current.getTableName(), current.getUniqueValue());
while(agr.next()){
agr.setValue('table_name' , '');
agr.setValue('table_sys_id' , '')
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 07:44 AM
@Kieran Anson - have you had a chance to look at this by chance?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 06:05 AM
Hi Tom, Sorry I didn't realise you replied.
From your shared script there are a few issues.
- When creating request management records, I'd really push to using the CartJS API as to create records how SN intends CartJS | ServiceNow Developers
- Attachments are transient before they're set to their final record destination.
You can use the following, after you have the newly redirected target record defined, to move the attachments
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments(current.getTableName(), current.getUniqueValue());
while(agr.next()){
agr.setValue('table_name' , '');
agr.setValue('table_sys_id' , '')
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 10:02 AM
Thanks @Kieran Anson , I was able to get this to work (code is below) using your code!
else if (approvedSoftware == 'Not Listed') {
current.setAbortAction(true);
// Create a Service Request
var request = new GlideRecord('sc_request');
request.initialize();
request.short_description = producer.caller_id.getDisplayValue() + " wants to deploy this application install package that needs to be reviewed/approved: " + producer.enter_the_name_of_the_install_package;
request.description = "Install package name: " + producer.enter_the_name_of_the_install_package + "\n" +
"Install package description: " + producer.enter_a_description_of_the_install_package + "\n" +
"Additional details on request:" + "\n" + long_description;
request.watch_list = list;
var requestSysId = request.insert(); // Insert the record and get its sys_id
// Move attachments from the current record to the new sc_request record
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.getUniqueValue());
attachment.query();
while (attachment.next()) {
attachment.table_name = 'sc_request';
attachment.table_sys_id = requestSysId;
attachment.update();
}
// Redirect to the Service Request details page
producer.portal_redirect = 'https://psecudev.service-now.com/kb?id=ticket&is_new_order=true&table=sc_request&sys_id=' + requestSysId;
}