- 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-11-2022 06:04 AM
Thanks
I'll create another thread with this other issue.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-11-2022 06:05 AM
discussion can continue in this thread as well
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader