
- 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-30-2023 04:21 AM
You do not need to set the content type as we are sending binary in body. You might have to reference third Party API Documentation for content type if needed, as it is different for each api/third party.
Can you please mark my answer as helpful or correct, if it resolve your doubts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2023 10:58 PM
Hello Mehta,
I am still not able to transfer pdf/word/excel format documents from ServiceNow to Zendesk. Only image and text files are transferred from the above method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 02:45 AM
Can you please check documentation or try by not setting content type in header. Do check whether the tool can accept different content type apart from the one you have mentioned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2024 04:24 AM
Hi,
Any worked solution for this. i have same scenario. how did you implemented.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 01:23 AM
Hello Ahmer,
any solution found