Catalog item attachment send as zip file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 11:54 AM
How to send ritm attachment as zip file to the email of the requestor?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 04:24 PM
Hi, starting with Tokyo release Flow designed provides a ZIp functionality,
So you should be able to create a flow or subflow that you can use to zip your RITM attachment and then email to your user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2023 12:16 AM
HI @sukran ,
I trust you are doing great.
- Retrieve the RITM record using the unique identifier (sys_id) or any other suitable query.
- Get the email address of the requestor associated with the RITM.
- Create a zip file containing the attachment file(s) from the RITM record.
- Attach the zip file to an email and send it to the requestor's email address.
Here's an example code snippet to accomplish this in ServiceNow using server-side scripting (such as in a Business Rule or Script Include):
// Step 1: Retrieve the RITM record
var ritmSysId = '<RITM_sys_id>'; // Replace with the actual RITM sys_id
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(ritmSysId)) {
// Step 2: Get the requestor's email address
var requestorEmail = ritmGr.variables.requested_for.email.toString();
// Step 3: Create a zip file containing the attachment(s)
var attachments = [];
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_sys_id', ritmSysId);
attachmentGr.query();
while (attachmentGr.next()) {
attachments.push(attachmentGr);
}
// Step 4: Attach the zip file and send the email
var zipFile = new GlideZip();
for (var i = 0; i < attachments.length; i++) {
var attachment = attachments[i];
var fileContent = new GlideSysAttachment().getContent(attachment);
zipFile.addBase64TextFile(attachment.file_name, fileContent);
}
var email = new GlideEmailOutbound();
email.setSubject('Attachment(s) from your Requested Item');
email.setBody('Please find the attachment(s) requested.');
email.addRecipient(requestorEmail);
email.addAttachment(zipFile.getBytes(), 'attachments.zip');
email.send();
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2023 07:57 AM
Awesome @Amit Gujarathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2023 08:24 AM - edited ‎06-27-2023 09:02 AM