How to copy attachments from incident to problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2022 11:30 PM
When we are trying to create problem from incident, the attachments are not copying / getting duplicate vice versa.
When: on Update
Condition: Problem is not Empty
function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('problem');
gr.addQuery('sys_id',current.problem);
gr.query();
if(gr.next())
{
gr.problem = current.sys_id;
gr.update();
}
var temp = GlideSysAttachment.copy('incident',current.sys_id,'problem',current.problem);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 03:17 AM - edited 12-26-2022 03:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 03:59 AM - edited 12-26-2022 04:01 AM
Try this code.
var targetGlideRecord = new GlideRecord("problem");
targetGlideRecord.get(current.problem_id);
var glideSysAttachmentRef = new GlideSysAttachment();
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('table_name', current.getTableName());
gr.query();
// use while loop insteed of if for multiple attachment
if (gr.next()) {
glideSysAttachmentRef.writeContentStream(targetGlideRecord, gr.getValue('file_name'), gr.getValue('content_type'), glideSysAttachmentRef.getContentStream(gr.getValue('sys_id')));
}
If your question is solved, please close the topic by marking my answer "Accept as Solution". This will help others searching for a similar question and will remove the topic from the unsolved list.