Has Attachment business rule

Rick Mann
Tera Expert

I've implemented the "Has Attachment" business rule on the task table, which works great. Does anyone know if there is a way to run the rule (or modify it) to run against existing records that may have an attachment and update the flag?

http://wiki.service-now.com/index.php?title=Useful_Attachment_Scripts

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();
}
}

10 REPLIES 10

Hi



Thanks for your quick response.


Actually i am also using the same script and in same conditions, but problem is arising only for the [sc_request] table.



But i found the pit fall in this BR.


This Business rule is triggered when the attachment is inserted, but at that time the request is not made. It take some fraction of time to build a record in the Request table after the attachment is inserted.



So i have made a separate Business rule on sc_request table that do the same work. and its working good as expected for my requirement.



Again a big thanks for your response to my query.



Thanks


Fatima Khan