Check Attachment Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2011 08:27 AM
I am trying to implement the check attachment script for our incident application, but have not been able to get the script to run. Has anyone tried to implement this? I could use some pointers, I am not familiar with scripting only the general concepts.
I have followed the steps of creating the customized field as well, but have been extremely unsuccessful.
Thanks!
Script:
checkAttachment();
function checkAttachment(){
// if inserting then the task has an attachment
if (current.operation() == 'insert') {
hasAttachment('true');
}
// if deleting attachment check for other attachments
if (current.operation() == 'delete') {
var attachments = new GlideRecord('sys_attachment');
attachments.addQuery('table_sys_id',current.table_sys_id);
attachments.query();
// if no other attachments task does not have attachment
if (!attachments.next()) {
hasAttachment('false');
}
}
}
function hasAttachment(answer) {
var task = new GlideRecord('task');
task.addQuery('sys_id',current.table_sys_id);
task.query();
if(task.next()) {
task.u_has_attachments = answer;
task.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2014 08:09 AM
Not sure about this. I think Oliver Dösereck was right. You must make sure that your task table has the u_has_attachments field created.
Check your dictionary
(
)
I would take another approach.
Could you try this?
Business Rule on table sys_attachment
After
insert, update and delete checked
Script :
var task = new GlideRecord('task');
if (task.get(current.table_sys_id)){
var attachment_found = false;
var attachments = new GlideRecord('sys_attachment');
attachments.addQuery('table_sys_id',current.table_sys_id);
attachments.query();
// if no other attachments task does not have attachment
if (attachments.hasNext()) {
attachment_found = true;
}
if (task.u_has_attachments != attachment_found) {
task.u_has_attachments = attachment_found;
task.u_has_attachments.update();
}