- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 04:05 AM
Hello!
I have a script action that adds a work note to the ticket when an attachment on an incoming email is discarded by ServiceNow. The next requirement is to get the file names of the discarded files and it to the work note. I tried updating my working script but it's not working as I intended.
var target_table = current.target_table;
var target = current.instance;
var gr = new GlideRecord(current.target_table);
gr.addQuery('sys_id', target);
gr.query();
if (gr.next()) {
var gr2 = new GlideRecord('sys_email_attachment');
gr2.addQuery('email.sys_id', target);
gr2.addQuery('action', 'discarded');
gr2.query();
if (gr2.next()) {
if (target_table == "incident" || target_table == 'sc_task') {
gr.work_notes = "One or more attachments from an email sent by " + current.user_id.name + " with subject " + current.subject + " were discarded. " + gr2.file_name;
gr.update();
}
}
Please help!
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-09-2022 01:13 AM
Hi,
yes like this
var target_table = current.target_table;
var target = current.instance;
var sysId = current.sys_id;
var gr = new GlideRecord(current.target_table);
gr.addQuery('sys_id', target);
gr.query();
if (gr.next()) {
var fileNameArr = [];
var gr2 = new GlideRecord('sys_email_attachment');
gr2.addQuery('email.sys_id', sysId);
gr2.addQuery('action', 'discarded');
gr2.query();
while(gr2.next()) {
fileNameArr.push(gr2.getValue('file_name'));
}
if (target_table == "incident" || target_table == 'sc_task') {
gr.work_notes = "One or more attachments from an email sent by " + current.user_id.name + " with subject " + current.subject + " were discarded. " + fileNameArr.join('\n');
gr.update();
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 04:13 AM
Hi,
update as this
var target_table = current.target_table;
var target = current.instance;
var sysId = current.sys_id;
var gr = new GlideRecord(current.target_table);
gr.addQuery('sys_id', target);
gr.query();
if (gr.next()) {
var fileNameArr = [];
var gr2 = new GlideRecord('sys_email_attachment');
gr2.addQuery('email.sys_id', sysId);
gr2.addQuery('action', 'discarded');
gr2.query();
while(gr2.next()) {
fileNameArr.push(gr2.attachment.getDisplayValue());
}
if (target_table == "incident" || target_table == 'sc_task') {
gr.work_notes = "One or more attachments from an email sent by " + current.user_id.name + " with subject " + current.subject + " were discarded. " + fileNameArr.toString();
gr.update();
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 10:47 PM
I'm afraid this did not work. For our instance, the attachment field is not populated but the file_name field which is a string/text field. I tried updating
fileNameArr.push(gr2.attachment.getDisplayValue());
to
fileNameArr.push(gr2.file_name.getDisplayValue());
OR
fileNameArr.push(gr2.file_name);
but it did not work.
Please help!
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 10:50 PM
did it go inside the while loop and get file_name value?
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 11:04 PM
I'm so sorry I'm not good at troubleshooting scripts.
How do I check that it went inside the while loop?