- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 05:19 AM
Hi community,
I'm looking for delete attachment when my task is closed (to save storage)
Actually i'have a workflow :
And i written this script but it doesn't work
Have you got a solution to help me ?
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 05:35 AM
Hi Raphael,
I think the main problem is that the part of the attachment deletion is not within the while-loop of the scTask.
I'm not sure for what you'll need the scTaskID concatenated string, but I refactored your script snippet a bit.
It is untested but this might work:
var scTaskID = '';
var seperator = '';
var scTask = new GlideRecord('sc_task');
scTask.addQuery('request_item', current.sys_id);
scTask.query();
while(scTask.next()){
var currentTaskID = scTask.getValue('sys_id');
scTaskID += seperator + currentTaskID;
seperator = ',';
//now delete the attachment
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', currentTaskID);
gr.addQuery('table_name', 'sc_task'); //to make 100% sure we delete from the correct table
gr.deleteMultiple();
}
Best regards,
Basti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 06:32 AM
I try your solution and i think it's working but
the answer is : Delete operation against 'sys_attachment' from scope 'x_43484_font_servi' has been refused due to the table's cross-scope access policy
I'm not fluent in english but i think it's : Hey man you can't do it

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 06:34 AM
Hi Raphael,
Please check Application Access Setting of table "sys_attachment". OOTB "Can Delete" option is unchecked, it means that from other scope you cannot make a delete operation on the attachment table unless and until you explicitly allow this(i.e Set Checkbox "Can Delete" to true).
You can specify what application artifacts are available to other custom applications in different application scopes. These permissions are in addition to the standard access controls (ACLs) that determine whether users can access data in the custom application table from the user interface.
Application Access Settings - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 06:37 AM
Hi Raphael,
This has to do with scoped applications and the protection they have between tables. While you COULD go to the sys_attachment table and change the application access to allow other applications delete access (see image below), this would decrease the protection between the various applications and sys_attachment.
Is there a reason you are concerned about the storage used by sys_attachment? Not having to worry about this is one of the features of cloud systems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2016 07:06 AM
Hi ctomasi,
For the storage it's not my decision, it's the serviceNow manager (i'm just a developper junior ^^) He said and i do . But he explained me, it's because every instance have XXXXX MB and he is full (and instances are expensives).
thanks for the application scopes now it's working !