Check if new attachment is added to a record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:47 AM
Hi All,
Is there a way to check if there is any new attachment added to a record with name "demo" and if added then run an update br on that record? There might be multiple attachments added so i need to run the br only if the attachment with name containing "demo" is added. I will not be able to write a script directly on the attachment table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:57 AM
you cannot have business rule on the actual table as attachment gets added sys_attachment table
If you wish to have some logic based on file name added then have after insert BR on sys_attachment table
Condition; current.table_name == 'incident' && current.file_name.indexOf('demo') > -1
Script:
// your logic
OR
You can also have after update BR on incident/your table and Query sys_attachment table to get the latest file and name as demo
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:02 AM
Hi @MaharshiC
(function() {
var attachments = document.getElementsByClassName('get-attachment');
var foundDemo = false;
for (var i = 0; i < attachments.length; i++) {
if (attachments[i].innerText.toLowerCase().indexOf('demo') !== -1) {
foundDemo = true;
break;
}
}
if (foundDemo) {
alert('New attachment named "demo" found!');
} else {
alert('No new "demo" attachment found.');
}
})();
Let me know if it works
Thanks,
Raj