Web Services (Server) - fdlGitHub/ServiceNow GitHub Wiki

var imageGR = new GlideRecord('db_image'); imageGR.initialize(); imageGR.name = 'support2.png'; imageGR.category = 'kb'; // Knowledge Management var imageId = imageGR.insert();

var sm = new sn_ws.RESTMessageV2(); sm.setHttpMethod('get'); sm.setRequestHeader("Accept", "application/octet- stream"); sm.setBasicAuth('username', 'password');

// Set the EndPoint with the relative Attachment URI sm.setEndpoint('endpoint'); // Set where the answer will be saved, and the name of the attachment sm.saveResponseBodyAsAttachment('db_image', imageId, 'image');

// Run the Web Service var res = sm.execute(); gs.print(res.getStatusCode());

gs.print(res.getResponseAttachmentSysid());

var attachmentGR = new GlideRecord('sys_attachment'); attachmentGR.get(res.getResponseAttachmentSysid()); attachmentGR.table_name = 'ZZ_YYdb_image'; attachmentGR.content_type = 'image/png'; attachmentGR.update();

var imageGR = new GlideRecord('db_image'); imageGR.get(imageId);

gs.print(imageGR.image.getDisplayValue()); // Result is sys_id.iix