- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:06 AM
Hi Team,
Unable to receive correct files , getting corrupted attachments in REST inbound. receiving only text files.
Should be able to get PDF, JPG, PNG , excel files as welll..
below is my attachment handling code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:14 AM
are you writing this in scripted REST API?
Where are you writing this?
GlideSysAttachment write() method only works for plain text file such as .txt or .csv
If you are getting base64 encoded data then use this and it will work for all types
if (JSUtil.notNil(file_name) && JSUtil.notNil(content_type) && JSUtil.notNil(base64Data) && JSUtil.notNil(correlationID)) {
var caseForAttachment = new GlideRecord('sn_customerservice_case');
if (caseForAttachment.get('correlation_id', correlationID)) {
var eccGr = new GlideRecord('ecc_queue');
eccGr.initialize();
eccGr.setValue('agent', 'AttachmentCreator');
eccGr.setValue('topic', 'AttachmentCreator');
eccGr.setValue('name', file_name + ':' + content_type);
eccGr.setValue('source', 'sn_customerservice_case' + ':' + caseForAttachment.sys_id);
eccGr.setValue('payload', base64Data);
eccGr.insert();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:11 AM
https://www.servicenow.com/community/developer-forum/attachment-getting-corrupted/m-p/1494214
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:14 AM
are you writing this in scripted REST API?
Where are you writing this?
GlideSysAttachment write() method only works for plain text file such as .txt or .csv
If you are getting base64 encoded data then use this and it will work for all types
if (JSUtil.notNil(file_name) && JSUtil.notNil(content_type) && JSUtil.notNil(base64Data) && JSUtil.notNil(correlationID)) {
var caseForAttachment = new GlideRecord('sn_customerservice_case');
if (caseForAttachment.get('correlation_id', correlationID)) {
var eccGr = new GlideRecord('ecc_queue');
eccGr.initialize();
eccGr.setValue('agent', 'AttachmentCreator');
eccGr.setValue('topic', 'AttachmentCreator');
eccGr.setValue('name', file_name + ':' + content_type);
eccGr.setValue('source', 'sn_customerservice_case' + ':' + caseForAttachment.sys_id);
eccGr.setValue('payload', base64Data);
eccGr.insert();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:56 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 11:29 PM
Hi Ankur,
This worked perfectly. Now able to receive all formats of files.
Thanks a lot for your support.