The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Check Attachment Script

khsieh
Kilo Explorer

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

5 REPLIES 5

Oliver D_sereck
Giga Expert

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


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


I am having the exact same issue. Any ideas?


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