Inbound email action for attachment

nivethika
Tera Contributor

Hi Team,

 

When an external sender/vendor replies to the email sent by SNOW with attachments WITH the word #Success, the attachments SHOULD NOT be attached to the ticket in regardless of what format the attachments would be. Email content will still be attached to the ticket, and the activity will have the record of the email

i mean if there is word #success -- then that attachment should not add to that ticket.

 

When an external sender/vendor replies to the email sent by SNOW with attachments WITHOUT the word #Success, the attachments SHOULD be attached to the ticket in regardless of what format the attachments would be. Email content will still be attached to the ticket, and the activity will have the record of the email

i mean if there is no word #success --then  attachment should get attached to the ticket.

 

can anyone help me achieve this logic. 

4 REPLIES 4

GlideFather
Tera Patron

Hi @nivethika,

it does sound like a Business rule onBefore for sys_attachment table with the above conditions

EDIT: please, it shall not be referred as SNOW, instead go with ServiceNow or NOW

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Thank you @GlideFather .

 

this can achieve through business rule or inbound email action?

can you please elaborate in detail.

Laveena_A
Tera Contributor

Satish Rana1
Tera Contributor

Hi @nivethika ,

Create an Inbound action try this script:

 

(function runInboundEmailAction(email, email_action, event) {
var bodyText = email.body_text.toLowerCase();
var hasSuccessTag = bodyText.includes('#success');

gs.info('Inbound email received for ' + email.target + ' with #success: ' + hasSuccessTag);

// attach the email body as comments
var target = email.target;
if (target && target.isValidRecord()) {
target.comments = "Inbound Email:\n" + email.body_text;
target.update();
}

// Check and handle attachments
var attachments = email.getAttachments();
if (hasSuccessTag) {
// Reject all attachments if "#Success" is found
for (var i = 0; i < attachments.size(); i++) {
var attachment = attachments.get(i);
attachment.setState(GlideEmailAttachment.REJECTED);
}
gs.info("Attachments rejected due to presence of #Success in the email.");
} else {
// attachments will be saved by default
gs.info("Attachments will be accepted (no #Success tag found).");
}

})(email, email_action, event);

 

Please mark this helpful or accept the solution if it is useful.

Thank you