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 "Retrieved Update Set" and upload the xml. That will install the script helper.

Also make sure you can execute the helper by disabling API authentication, or setup the correct authentication.

Disable it by going to Scripted REST API and uncheck that authentication box.

Test script

Go to Fix script and look for Example - MP Upload.

Make sure to set these things

mpHelper.setHostDetails('incident', hostRecord);

mpHelper.addAttachment( 'file', attachmentId );

it must be named file


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  and attachment id
doUpload("ae8e06ccdb2010100c9db080399619b5","67ce4200db6010100c9db0803996195a")


;