how to avoid inserting duplicate file name in sys_attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 10:31 PM
Hi Team,
We are using order guide and have created a variable as attachment. We are cascading the variable in servicenow.
Based on no of RITM attachments are inserted to sys_attachment table. Could you please help me how to avoid the duplicates while inserting the attachment into sys_attachment table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 10:43 PM
Hi @Arun91 ,
This can be achieved by creating a before business rule on the sys_attachment table.
If there is a file with same name, same content type and of same size in bytes then the attachment upload is aborted.
The code for the same is as below
var attach = new GlideRecord(‘sys_attachment’);
attach.addQuery(‘table_sys_id’, current.table_sys_id);
attach.addQuery(‘table_name’, current.table_name);
attach.addQuery(‘file_name’, current.file_name);
attach.addQuery(‘content_type’, current.content_type);
attach.addQuery(‘size_bytes’, current.size_bytes);
attach.query();
if(attach.next()){
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 10:47 PM
HI,
If same file name we are using but content is different in that case it will aborted it. So it should compare both file name and content so that it will validate before inserting into sys_attachment table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2024 01:17 AM
@Arun91 , Refer to this Community Link , Make some tweaks as per your requirement
Regards,
Shyamkumar
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2024 11:00 PM
Hello @Arun91 ,
Can you please confirm you are on which version, seems issue has been fixed in recent version.
Regards,
CB