- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
2 hours ago
Requirement Overview:
If I want to attach the email that was forwarded to ServiceNow (which did not create a case) to the Resend your email notification, so that the recipient knows which email it was that did not create a case.
Solution:
1. Navigate to Inbound Actions
2. Create a new inbound action that has, for ex. Table = HR Workforce Administration, Action Type = Record Action and Type - Forward
3. Set the required conditions.
4. In the script section, write the following script:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var content = email.body_text;
var data = content.split("-----");
gs.include('validators');
var opened_for;
var ourUser = gs.getUser();
var parm1 = email.origemail;
var sender = email.from_sys_id;
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', sender);
grUser.query();
if (grUser.next()) {
opened_for = sender;
current.opened_for = opened_for;
current.subject_person = opened_for;
current.description = "To: " + email.direct + "\n" + "CC: " + email.copied + "\n" + "\n" + "\n" + data[0];
current.short_description = email.subject;
current.contact_type = 'email'; // Set the Contact type is Email
current.hr_service = gs.getProperty('sn_hr_core.demo_hr_service'); // Sys ID of HR Service
current.assignment_group = gs.getProperty('sn_hr_core.demo_group'); // Sys_id of demo_group
current.update();
var emailAsAttachment = new global.emailAsAttachmentUtil();
emailAsAttachment.createAttachment(email, current);
} else {
if (sender != gs.getProperty('sn_hr_core.hr_guest')) {
var grEmail = new GlideRecord('sys_email');
grEmail.get(sys_email.sys_id);
var emailAsAttachment1 = new global.emailAsAttachmentUtil();
emailAsAttachment1.createAttachment(email, grEmail);
gs.eventQueue("sn_hr_core.internal.autofwd.email", null, parm1, sys_email.sys_id);
} else {
gs.eventQueue("sn_hr_core.external.autofwd.email", null, parm1);
}
}
})(current, event, email, logger, classifier);
5. Navigate to Notifications and create a new notification
6. Select the table as HR Case(sn_hr_core_case) and do the configurations as per the screenshot below
7. Create a business rule to get and set the attachment to the above static notification
(function executeRule(current, previous) {
/*
Purpose: To get and set the current email.
*/
var grEmailAttachment = new GlideRecord('sys_email_attachment');
grEmailAttachment.addQuery("action_reason", "WC-Auto Forward Reply for Internal-Notification"); //set the custom line to action_reason fieldp
grEmailAttachment.orderByDesc('sys_created_on');
grEmailAttachment.setLimit(1);
grEmailAttachment.query();
if (grEmailAttachment.next()) {
grEmailAttachment.email = current.sys_id;
grEmailAttachment.update();
}
})(current, previous);
Now, just forward any email to your ServiceNow instance, and if you are an snc_internal user, then the notification will trigger with the subject "Please resend your email to help us assist you" and the attachment will be attached to this email if the inbound action fails to create a case.
If my article helped you, please mark it as helpful.
Thank you!
- 31 Views