- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 10:18 PM
I would like to convert the file attached to the RITM to Base 64.
I want a code that can be tested in Background Script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 10:43 PM
Did you test the script you shared? I'll share you the right script😁
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', ritm_sys_id);
attachment.query();
while(attachment.next()){
// Base64 Encoding
var gsa = GlideSysAttachment();
var base64 = GlideBase64.encode(gsa.getByte(attachment));
var encoding = GlideStringUtil.base64Encode(base64);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 10:43 PM
Did you test the script you shared? I'll share you the right script😁
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', ritm_sys_id);
attachment.query();
while(attachment.next()){
// Base64 Encoding
var gsa = GlideSysAttachment();
var base64 = GlideBase64.encode(gsa.getByte(attachment));
var encoding = GlideStringUtil.base64Encode(base64);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 10:45 PM
Hi @BoHyun Jung
Below link could be helpful :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:04 PM
@BoHyun Jung , What @Maddysunil Suggested Script looks good for Background Script and this Works Well
If you want to do this Dynamic later after your Test you can use below Snippet by Designing BR on Update , Insert on RITM (sc_req_item) Table
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.sys_id);
attachment.query();
if (attachment.next()) {
// Read the file content
var fileContent = new GlideSysAttachment().getContent(attachment);
// Convert to Base64
var base64File = GlideStringUtil.base64Encode(fileContent);
gs.info("Base64 encoded file content:\n" + base64File);
} else {
gs.info("No attachment found for RITM: " + ritmSysId);
}
}
Regards,
Shyamkumar
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 11:26 PM
Hi @BoHyun Jung
Please try the following BS-
var ritmSysId = 'your_ritm_sys_id_here';
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_name', 'sc_req_item');
attachmentGr.addQuery('table_sys_id', ritmSysId);
attachmentGr.query();
if (attachmentGr.next()) {
var sysAttachment = new GlideSysAttachment();
var attachmentStream = sysAttachment.getContentStream(attachmentGr.getUniqueValue());
var encodedString = GlideStringUtil.base64Encode(attachmentStream);
gs.info('Base64 of attachment: ' + encodedString);
} else {
gs.info('No attachments found for RITM with sys_id: ' + ritmSysId);
}
Please mark my answer helpful and correct.
Regards,
Amit