// ServiceNow

Copying files using the Attachment API

Copying a file using the Attachment API (sending an attachment to another ServiceNow instance using the API)

Script Include example:

var STUtil = Class.create();
STUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    sendAttach:function(argTargetTable, argCaseSysID, argINCFileName, argContentType, argFileSysID){
    gs.info("AVT attachmnet API EXECUTED: *** ");
        try{
    var instenceName = 'https://YOUR_INSTENCE_NAME.service-now.com/';	
    var endPoint = instenceName + 'api/now/attachment/file?table_name=' +
        argTargetTable + '&table_sys_id=' + argCaseSysID +
        '&file_name='+argINCFileName.replaceAll(" ","%20");
            
    var r = new sn_ws.RESTMessageV2();
        r.setAuthenticationProfile('basic','bd773d7a1b529d9066f96202b24bcb97'); //Veysel Test 
        r.setHttpMethod("POST");
        r.setEndpoint(endPoint);
        
        r.setRequestHeader("Content-Type",argContentType);
        r.setRequestHeader("Accept","Application/json");
        
        r.setRequestBodyFromAttachment(argFileSysID);
        
        var response = r.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        } catch(ex){
            var message = ex.message;
            gs.info("AVT attachmnet API Alert: " + message);
        }
        
},
    type: 'STUtil'
});

Calling the Script Include:

//table adı, kaydın sys_id si , ekin adı, ekin tipi, kopayalanacak ekin - sys_attachment tablosundaki sys_id si
var sonuc = new STUtil().sendAttach('ticket', 'd5d469ba975e59905374be7fe153afa6', 'jpg.jpg', 'image/jpeg', 'a52ace241b5a119066f96202b24bcba5');

 

// JOIN THE CONVERSATION

Share your experience

Bir sorunun, farklı bir çözümün veya eklemek istediğin bir notun var mı? Giriş yapmadan da yazabilirsin.

// KEEP READING

One more note.

All posts ↗︎