Attachment API kullanarak dosya kopyalama
Attachment API kullanarak dosya kopyalama ( başka bir servicenow instence’ına API kullanarak attachment gönderme )
Script include örneği:
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' });
Script include’u çağırma:
//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');