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
‎02-06-2012 12:24 PM
Hi,
Since you have copied the script 1:1 from here:
http://wiki.service-now.com/index.php?title=Useful_Attachment_Scripts
Make sure you have created the field properly (it must be "u_has_attachments")
Also make sure the business rule where the script is included is located on the sys_attachment table.
And that the business rule triggers after insert/delete
Also make sure your "u_has_attachments" field is on the TASK table, and that its the type of boolean.
Then you would have to display the u_has_attachments field in the list and/or on the form
I have tried this on the demo instance and it worked without problems (basic copy/paste)
Cheers,
OD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2014 11:22 PM
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
‎06-13-2014 01:06 PM
I am having the exact same issue. Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2014 07:07 AM
Hi Barry,
I have made a (async) BR on request[sc_request] table to set has attachment flag similarly and its working as expected.
I know i am a little late in replying on your comment.
Hope it works for you or you had already solved your issue.
Thanks
Fatima