Inbound mail script to check for attachments

anushad
Tera Expert

Hi ,

Can someone please help me to fix the below inbound mail script code.

Below code is written to verify whether the inbound email has attachments or not.If there are attachments then we have to setValue on a task and trigger an event. If not we have to abort the whole setValue action and trigger an event which sends an email notification . But both if(attachLog.next()) and else code parts are executing all the time. Instead of either one of the events both events are being triggered.

if (email.subject.contains("accept")) {

/var email_log = new GlideRecord('sys_email');
email_log.addQuery('uid', email.uid);
email_log.query();
if (email_log.next()) {
 var attachLog = new GlideRecord('sys_attachment');
attachLog.addQuery('table_sys_id', email_log.sys_id);
 attachLog.addQuery('table', 'sys_email');
attachLog.query();
 if (attachLog.next()) {
current.setValue("u_response"," accepted");
gs.info("In the inbound email action before triggering event");
gs.eventQueue('letter_response',current);
 }

else{

gs.info("In the inbound email action before triggering event");

gs.eventQueue('letter_response_attachdocs',current);

}
}

}

1 ACCEPTED SOLUTION

anushad
Tera Expert

I figured out what's wrong with the code attachLog.addQuery('table', 'sys_email'); the field name table in the query statement is what giving me the trouble , as it should be attachLog.addQuery('table_name', 'sys_email');

 

View solution in original post

9 REPLIES 9

Alikutty A
Tera Sage
Hi, Are you getting 2 logs when the email is send? i guess it is executing twice somehow. please check the inbound logs

There is no loop in the code emailLog.next() and attachLog.next() both are if conditions.

Jim Coyne
Kilo Patron

I'm assuming the single "/" in the second line of code is a typo and not really there in your Inbound Email Action, correct?  Is that the entire contents of the script?

And both of your "gs.info" calls are outputting the same string, so that may not be helping your debugging. 

That " / " is just a typo and the event "gs.eventQueue('letter_response_attachdocs',current)" in the else part will trigger a email notification. I am still receiving that email.

anushad
Tera Expert

I figured out what's wrong with the code attachLog.addQuery('table', 'sys_email'); the field name table in the query statement is what giving me the trouble , as it should be attachLog.addQuery('table_name', 'sys_email');