Salesforce Case attachment to ServiceNow via REST API not getting loaded in proper format
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi Experts,
I am using below given code in background script to load Salesforce attachments from case table to ServiceNow Incident table and it's working and attachments are getting loaded but when we download the attachments and view the content then it's giving error for format and not recognizing the content.
// Download binary from /Body endpoint
var r3 = new sn_ws.RESTMessageV2();
r3.setHttpMethod('GET');
r3.setEndpoint(baseUrl + '/services/data/v62.0/sobjects/Attachment/' + attachId + '/Body');
r3.setRequestHeader('Authorization', token);
//r3.setRequestHeader('Accept', 'application/octet-stream');
var fileResponse = r3.execute();
if (fileResponse.getStatusCode() !== 200) {
gs.error("Failed to get file: " + attachName + " from Salesforce: " + fileResponse.getStatusCode());
continue;
}
// Attach directly to ServiceNow record
var base64Bytes = GlideStringUtil.base64Encode(fileResponse.getBody()); // binary-as-string in scoped apps
gs.info(base64Bytes);
var gsa = new GlideSysAttachment();
gsa.write(cs,attachName,attachType,base64Bytes);
I am hitting the Salesforce attachment body endpoint and getting the raw file to encode in base 64 and using Attachment APIs to add with the record. I also tried without encoding and adding raw data directly to attachment table. Please help if I am making any mistake.
Labels:
- Labels:
-
IntegrationHub
0 REPLIES 0