Has Attachment business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2011 10:50 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2011 01:12 PM
John
Thanks for the script, it provides exactly what I need. I've done some other scripting in Service-Now, but the TableUtils and Glideaggregate are some new territory. I'll be at K11 this year and plan to sit in some of the scripting sessions.
Thanks again for your time!
Rick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2011 06:25 AM
IF a user attaches a file to a record when they first create the task (ie. before the first save) then the "has attachment" business rule doesn't seem to work (presumably because the task record has not been written to the database yet so the task query fails to find the task record).
Apart from querying the sys_attachment table everytime a task is inserted to see if it has any attachments, does anyone have a more elegant solution to ensuring that the has attachments field is always correct ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2012 10:02 PM
I've tried "Has Attachment" business rule and background script on the task table and they worked perfectly. For some reason they don't work on the Kb_knowledge table. Do you know why that might be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2014 04:54 AM
Hi rmann56
I have applied this Business rule, its working fine as expected other then its not setting the has attachment flag to true for sc_request table and it is having the attachment attach to it.
When i attach a file at the checkout screen( to be more specific).
If any suggestion please let me know. Waiting for a positive feedback on this query.
Thanks
Fatima
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2014 12:07 PM
Hello Fatima
I'm not certain why the attachment business rule would not work on the sc_request table. I confirmed that the rule is working in our environment by manually adding an attachment to a request. We don't attach anything at the request level, but rather at the sc_req_item level and I did confirm that our request items are flagging correctly when we add an attachment to the record. Do you have any ACLs that may be preventing an update to the record? Let me know and good luck.
Here is the business rule detail, I'm using:
Business rule fires: After insert and delete
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();
}
}