update the existing attachment by changing the table name to incident and the table sysid to the inc

Community Alums
Not applicable

Hello, 

 

I need help with the below code, i don't use the copy attachment but rather update the existing attachment by changing the table name to incident and the table sysid to the incident sysid. which part of the code to i update this

 

  var ee = a.insert();
    var checker = new GlideRecord('incident');
    checker.get(ee);

var attachment = new GlideSysAttachment();
var interactionSysID = current.sys_id;
var intGR = new GlideRecord('interaction');
intGR.get(interactionSysID);

var copiedAttachments = attachment.copy('interaction', interactionSysID,'incident', intGR.getValue('incident_id'));
gs.info('Copied attachments: ' + copiedAttachments);
2 REPLIES 2

Community Alums
Not applicable

Hi @Community Alums ,

Please refer to sample code :

Table - Requested Item
When to Run - Before Update
Condition - Send Attachments to True
Scripts - 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var copy = new GlideRecord('problem');
    copy.addQuery('parent', current.getUniqueValue());
    copy.query();
    if (copy.next()) {
        GlideSysAttachment.copy('incident', current.getUniqueValue(), 'problem', copy.getUniqueValue());
    }
})(current, previous);

 

Community Alums
Not applicable

can i add this code in the record producer? what i want to achieve is in the sys_attachment table update the table sys id to the incident table for the attachment to show in the incident record. 

GlideSysAttachment.copy('sys_attachment', current.attachment.sys_id, 'incident', current.ee.sys_id);

 

does this make sense?