- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 08:03 PM
This is poor logic, if there is an attachment file with the same name that already exists. It's possible for multiple users to upload identical files. Better to use an After Business Rule on the record producer table to find the attachment via the table_sys_id and update the table_name via glideRecord update. Also, what would you do if there are multiple attachments? Here's an example of a script include, and it's working well for me.
var AssociateCaseAttachment = Class.create();
AssociateCaseAttachment.prototype = {
initialize: function() {},
updateCaseAttachment: function(sys_id) {
if (!sys_id) {
return;
}
var grAttach = new GlideRecord('sys_attachment');
grAttach.setLimit(10);
grAttach.addEncodedQuery('table_sys_id=' + sys_id);
grAttach.query();
while (grAttach.next()) {
grAttach.table_name = 'YOUR Table NAME';
grAttach.update();
}
},
type: 'AssociateCaseAttachment'
};