Previously attached attachment not getting ebonded to 3rd party ServicNow

mr_zia
Giga Guru

Dear Team,

 

I am able to send attachment to 3rd party, for this I have written a After BR on Insert on the sys_attachment table.

But my issue is, we get incident from internal teams with attached attachment, now if we try to ebond the same incident to 3rd party Servicenow the previously attached attachments do not pass, but there is no issue if attachment is added to the ticket after the ticket is saved to ebonded trigger group.

 

How can we ebond previously attached attachments OR during the ebond insert?

 

Any help would be highly appreciated.

 

 

MY BR SCRIPT:

(function executeRule(current, previous /*null when async*/ ) {
gs.addInfoMessage("SN Attachment Trigger");
   var target = new GlideRecord('incident');
    target.addQuery("sys_id", current.table_sys_id);
    target.addEncodedQuery('active=true^u_vendor_reference_sysidISNOTEMPTY^state!=7');
    target.query();
    while (target.next()) {    
        var sa = new GlideSysAttachment();
        var binData = sa.getBytes(current);
        var base64Data = GlideStringUtil.base64Encode(binData);
        var name = current.file_name + ":" + current.content_type;
        var source = 'u_sn_b2b_itsm_gateway:' + target.u_vendor_reference_sysid;
        var requestAttachment = new sn_ws.RESTMessageV2('SN Integration', 'Send Attachment');
        requestAttachment.setRequestHeader("Accept", "application/json");
        requestAttachment.setRequestHeader('Content-Type', 'application/json');
        requestAttachment.setRequestBody("{\"agent\":\"AttachmentCreator\",\"topic\":\"AttachmentCreator\",\"source\":\""+source+"\",\"name\":\""+name+"\",\"payload\":\""+base64Data+"\"}");
         var requestbody = requestAttachment.getRequestBody();
         var response = requestAttachment.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        gs.addInfoMessage("RequestBody"+requestbody);
        gs.addInfoMessage("ResponseBody"+responseBody+"\n"+httpStatus);

    }

})(current, previous);
1 REPLY 1

Mark Manders
Mega Patron

Do you run this on insert of an attachment? 

Maybe use the script to also include attachments when the incident integration itself is triggered? Query to the attachment table from the incident and sent the attachments at that moment.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark