Check if new attachment is added to a record

MaharshiC
Tera Contributor

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.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

raj chavan
Tera Guru

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 




Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj