Please help with copy attachments script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 09:08 AM
Hello,
I would like to create a UI Action that copies an existing ritm along with all the attachments to a new ritm. However, I got stuck on copying attachments over to the new ritm. Could somebody please review the following code and provide suggestions on how I can accomplish this task? Thank you
**This part works**
var getSysId = current.getUniqueValue();
current.setValue('number','');
CreateSysID = current.insert()
**This part of the code did not work**
var attach = new GlideSysAttachment();
attach.copy('sc_req_item', current.sys_id, 'sc_req_item', current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 09:26 AM
Please discard my posted, because I figured it out where I screwed up.
I need to pass in "getSysID" and "CreateSysID"
attach.copy('sc_req_item', getSysId, 'sc_req_item', CreateSysID);
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 10:59 AM
Can you try this-
// Create a new RITM
var newRITM = new GlideRecord('sc_req_item');
newRITM.initialize();
newRITM.setValue('number', '');
var newRITMsys_id = newRITM.insert();
// Copy attachments from the original RITM to the new RITM
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.query();
while (attachmentGR.next()) {
var attachment = new GlideSysAttachment();
attachment.copy('sc_req_item', current.sys_id, 'sc_req_item', newRITMsys_id, attachmentGR.getUniqueValue());
}
gs.addInfoMessage('RITM copied successfully along with attachments.');
Please mark my answer helpful and correct.
Regards,
Amit