- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 11:45 AM
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);
}
}
}
Solved! Go to Solution.
- 2,581 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 07:39 AM
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');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 06:26 PM
check below thread if that may help
https://community.servicenow.com/community?id=community_question&sys_id=ffd01ba9dbdcdbc01dcaf3231f96194f
thanks
siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 08:24 PM
Thanks for the reply that post is related to size of the attachment.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 09:39 PM
adding one sample code which you can use to check if email has an attachment or not.
//Query the sys_email table so we can get the logged email's sys id, this is used later to look for attachments.
var email_log = new GlideRecord('sys_email');
email_log.addQuery('uid', email.uid); //Since we are calling this from an inbound email action, we need to lookup this incoming uid in the sys_email table.
email_log.query();
//Make sure we can find the email in the email log
if (email_log.next()) {
//Query our attachment table
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()) {
//Do Stuff
}
}
based on the above code you can set the value . give a try. let us know if you stuck somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2018 05:44 AM
I have same code and its giving me a problem by executing both if(attachLog.next()) and else code parts.
I have included my code in the question.