Avoid duplicate attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 01:13 PM
I have this before BR on sys_attachment table where I want to filter out duplicate attachments for the incident table. So if the user tries to add a file that's already present on the incident then it's not possible.
It seems to work on London release but not on Kingston - the manage attachments prompt just hangs when I activate the BR on Kingston.
Any suggestions to why it doesn't work on Kingston ?
Condition : current.table == 'incident'
Script:
var sysId = current.getValue('table_sys_id');
var fileName = current.getValue('file_name');
var foundDuplicate = false;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sysId);
gr.query();
while (gr.next()){
if (gr.getValue('file_name') === fileName){
gs.log('Duplicate filename found in incident, action should be aborted');
foundDuplicate = true;
}
}
if (foundDuplicate){
current.setAbortAction(true);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 09:41 PM
Hi Kim,
What type of business rule is this? Is this before insert?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 09:44 PM
Hi
Try this below in your before BR ;-
var fname= new GlideRecord('sys_attachment');
fname.addQuery('table_sys_id', current.table_sys_id);
fname.addQuery('table_name', current.table_name);
fname.addQuery('file_name', current.file_name);
fname.addQuery('content_type', current.content_type);
fname.addQuery('size_bytes', current.size_bytes);
fname.query();
if(fname.next()){
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 11:45 PM
Hi Omkar,
Thanks for your suggestion - I tried your code in my before business rule but it had the same effect. The prompt just hangs and nothing happens. It seems like the abortaction is executed but the prompt is never closed after that.
It seems to work fine on London but not on Kingston.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2018 11:47 PM
Hi
So maybe this is causing due to version issue. If you try with page reload after the abort action is performed you'll be suprised.
Anyways Thanks.