Prevent Duplicate Attachments insertion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2018 02:13 PM
I have a requirement to display an alert or message when someone tries to insert a attachment of duplicate file name on some record. Can some one guide me how can this be achieved?
I have written a script on 'sys_attachment' table, to abort inserting a new record when some one tries to attach a file with same name of already existing one.
Here is the script:
(function executeRule(current, previous /*null when async*/) {
var iso_attach= new GlideRecord('sys_attachment');
iso_attach.addQuery('table_name', 'u_details');
iso_attach.addQuery('file_name', current.file_name);
iso_attach.addQuery('table_sys_id', current.table_sys_id);
iso_attach.query();
if(iso_attach.next()){
gs.addInfoMessage("hello");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2019 11:53 PM
Hi Vishal,
When I tried this I'm getting the log error as below and the Attachment popup box is not getting closed.
Exception while processing attachment: null: java.lang.NullPointerException: com.glide.ui.SysAttachmentInputStream.read(SysAttachmentInputStream.java:99)
javax.imageio.stream.MemoryCache.loadFromStream(MemoryCache.java:113)
javax.imageio.stream.MemoryCacheImageInputStream.read(MemoryCacheImageInputStream.java:110)
javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:351)
javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:361)
com.sun.imageio.plugins.png.PNGImageReader.readHeader(PNGImageReader.java:232)
com.sun.imageio.plugins.png.PNGImageReader.getWidth(PNGImageReader.java:1369)
com.glide.ui.SysAttachment.getImageDimensions(SysAttachment.java:2280)
com.glide.ui.SysAttachment.setImageDimensions(SysAttachment.java:2309)
com.glide.ui.SysAttachment.writeParts(SysAttachment.java:313)
com.glide.ui.SysAttachment.processRequest(SysAttachment.java:245)
com.glide.processors.AttachmentProcessor.process(AttachmentProcessor.java:76)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:474)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:199)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:178)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:167)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:31)
com.glide.sys.Transaction.run(Transaction.java:2037)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 12:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 02:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2019 11:11 PM
Yes this works. I have an additional requirement: The above script prevents the users to upload duplicate files and I can display an error message. But the file still shows up in the attachments list until the record is refreshed (attached screenshot). Is there any way to prevent this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2019 11:31 PM
Hi,
Use gs.setRedirect to the record so that the page gets loaded on error.
Mark the comment as helpful if this helps.