
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 12:40 PM
1. I created a Rest Message.
2. I created a Business Rule on the attachment Table.
3. I created one incident to add an attachment and trigger the business rule but the attachment pass in base 64 format only.
Business Rule-----------------------
var a = current.sys_id;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', a);
gr.query();
if (gr.next()) {
var StringUtil = new GlideStringUtil();
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
encData = StringUtil.base64Encode(binData);
}
try {
attachmentRec = new GlideRecord("incident");
attachmentRec.addQuery("sys_id", current.table_sys_id);
attachmentRec.query();
while (attachmentRec.next()) {
ZendeskNumber = attachmentRec.u_zendesk_external_inc_number;
}
body.content_type = current.content_type + "";
body.u_zendesk_external_inc_number = ZendeskNumber + "";
body.number = attachmentRec.number + "";
body.file_name = current.file_name + "";
// body.base_64_bytes = binData + "";
body = JSON.stringify(body);
var r = new sn_ws.RESTMessageV2('', '');
r.setStringParameterNoEscape('file_name', current.file_name);
r.setRequestBody(body);
response = r.execute();
responseBody = response.getBody();
requestBody = r.getRequestBody();
httpStatus = response.getStatusCode();
jsonObject = JSON.parse(responseBody);
sysID = jsonObject.result.sys_id;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2023 01:58 AM
If you want to sent file as binary as a request body then you can use below code. It basically convert the file into binary and set the request body. But you wont be able to sent json or any other parameter in requested body. You might need to use query parameter or header to sent other details depending on the API document.
var r = new sn_ws.RESTMessageV2('Rest Message', 'Upload');
r.setRequestBodyFromAttachment(current.sys_id); //sys_id of attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 06:39 AM
Do you want to set the request body as binary or there will be a json format that you need to sent as request body to respective api?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2023 12:26 AM
This is the request api body:
{
"request":
{
"comment": {"body": "123",
"uploads":["token "]
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2023 01:58 AM
If you want to sent file as binary as a request body then you can use below code. It basically convert the file into binary and set the request body. But you wont be able to sent json or any other parameter in requested body. You might need to use query parameter or header to sent other details depending on the API document.
var r = new sn_ws.RESTMessageV2('Rest Message', 'Upload');
r.setRequestBodyFromAttachment(current.sys_id); //sys_id of attachment

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2023 03:45 AM
Thank you for the solution. I am able to send Text attachments from ServiceNow to Zendesk. However when I am trying to attach PDF/PNG or any other format with Content-Type as multipart/form-data. It is not working.