How to copy attachments from incident to problem

Shiva prasad t
Tera Guru

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);

 

6 REPLIES 6

Dinesh
Tera Guru

@shloke04 can you tell me form where you can get below data

Dinesh_0-1672053407265.png

 

Omkar Ranjane
Tera Guru

Hi @Shiva prasad t 

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.