var mp = new UnifiMultipartHelper();
// We need a record to link the temporary attachment to.
// (Default is the the sys_user record of the calling user)
// For Unifi this is likely to be the HTTPRequest record
// Let's hang it off a record we created earlier and stored in 'grHost'
// Alternatively, we could call setHostDetails( table_name, sys_id )
// When adding an attachment we need to specify two or three things
// - the name of the form field that the target is expecting
// - the sys_id of the attachment to add
// - (optional) the file name; if not supplied it will be taken from the attachment
// We could add more text or attchment parts here
// Generate the temporary attachment
// We can now use the generated attachment along with the boundary string
// to send the multipart body to the other system
var req = new sn_ws.RESTMessageV2();
// getContentType returns the content-type string including the boundary
// e.g. multipart/form-data; boundary="xxxxxxxxxxxx"
// getBodyId returns the sys_id of the multipart attachment
req.setEndpoint( /* the url */ );
req.setAuthenticationProfile('basic',/* the auth profile */);
var resp = req.execute();
// Once we have sent the body we can delete the temporary attachment