Decode base64 field and add to record as attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 09:47 AM
I have a field on a case form that is populated with a base64 value. I would like to take that string and convert it back into an image and attach that image to the case. Has anyone had any success in doing this? Thank you in advance for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 08:56 AM
@Ankur Bawiskar Has anyone found the solution to this ? Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:44 AM
Hi Ankur,
I have same issue of @rcard11
I am able to attach the attachment to target case record but attachment is not supporting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 11:33 AM
@rcard11 hey could you make it work somehow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 07:50 PM - edited 10-19-2023 07:50 PM
Hi @rcard11 @Vinicius Luz1 @Shreya , try this code
var attachment = new GlideSysAttachment();
/*If is a Business Rule, you can use the current */
var current= new GlideRecord('case_table');
var caseSYSID= 'case_sys_id';
current.get(case_sys_id);
var fileName = 'example.txt';
var contentType = 'text/csv';
var base64Encodedcontent = current.base64_field
var agr = attachment.writeBase64(rec, fileName, contentType, base64Encodedcontent);
gs.info('The attachment sys_id is: ' + agr);
If my answer helped you, please mark my answer as helpful.
Vanderlei Catione Junior | LinkedIn
Senior ServicePortal Developer / TechLead at The Cloud People
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 06:07 PM
I am working with a similar issue, but my contentType is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" for an XLSX file, but its not working.
Below is a portion of the code where 'contents' contains a base64 string that should be ok and work properly:
var fileName = fname + ".xlsx";
var gr = new GlideRecord('sys_properties');
gr.initialize();
gr.setValue('property_name', 'excel');
gr.insert();
var record_sys_id = gr.sys_id;
var rec = new GlideRecord('sys_properties');
rec.get(record_sys_id);
var contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var base64Encodedcontent = contents;
var attachment = new GlideSysAttachment();
var agr = attachment.write( rec, fileName, contentType, base64Encodedcontent);
action.setRedirectURL("/sys_attachment.do?sys_id=" + agr);
gs.info('The attachment sys_id is: ' + agr);