Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »



Install multipart/data script helper

To send multipart/form data from ServiceNow you will need to install the helper script linked:

https://docs.thewhitespace.io/unifi/1.5/multipart_form_data.html#wsmultiparthelper

Download the xml and goto 

Test script

function doUpload( hostRecord, attachmentId ) {
var mpHelper = new MultipartHelper();

mpHelper.setHostDetails('incident', hostRecord);

//mpHelper.setHostRecord( hostRecord );
mpHelper.addAttachment( 'file', attachmentId );

// this uses the loopback API to create a multipart-formatted payload.
mpHelper.createBody();

// we create the real rest message, and attach the multipart attachment.
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setEndpoint( 'https://myserver.rixter.se/rest/restfulintegrator/1.0/incoming/files/5f416862-4328-4ecd-9b9f-b378ffff3ecc?key=JIRA-2');

restMessage.setBasicAuth("demo","demo123");
restMessage.setHttpMethod( 'POST' );
restMessage.setRequestHeader("File", 'sys_remote_update_set_d5a54f904fb12300402ff9aba310c7c3.xml');
restMessage.setRequestHeader("Multipart", "true");

// getContentType returns the content-type string including the boundary
// e.g. multipart/form-data; boundary="xxxxxxxxxxxx"
restMessage.setRequestHeader('Content-Type', mpHelper.getContentType());

// getBodyId returns the sys_id of the multipart attachment
restMessage.setRequestBodyFromAttachment(mpHelper.getBodyId());

var restResponse = restMessage.execute();

// Once we have sent the body we can delete the temporary attachment
mpHelper.deleteBody();

return restResponse.getBody();
}




//inc id attachment id
doUpload("ae8e06ccdb2010100c9db080399619b5","67ce4200db6010100c9db0803996195a")


;



  • No labels