Check if an attachment is added in current update of record

deepakvednegi
Giga Contributor

Hi
I need to check if an attachment has been updated to the record. on the basis of that i need to Run some function.
Can this be possible?

The skeleton can be like this:

 

if(an attacment added){
yes();
else
No();

 

I thought of a soultion to write an After "Insert " business rule on "sys_attachment" table, to check if an attachment is added for the current change reuqest.
But dont know how to proceed.
Any ideas???

 

Regards

Deepak

4 REPLIES 4

Subhajit1
Giga Guru

Hi Deepak,


There is a function called hasAttachments() that checks if the current Record has attachments or not.


Or you can query the sys_attachment table with the current Updated record if the Count changes or not.



Thanks,


Subhajit


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Deepak,



Please refer section 8.16 in below wiki link for more info


http://wiki.servicenow.com/index.php?title=GlideRecord


Script:


var inc = new GlideRecord("sys_attachment");


inc.addQuery("table_name", "incident");


inc.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(15)');//check if user has added attachment in last 15minutes


inc.query();


while(inc.next())


{


}



Thanks,


Pradeep Sharma


Rohit Khaire
Mega Contributor

Hi Deepak ,



You can use use hasAttachment method to check whether current record carrying any attachment or not in your IF condition .


or you can use glide in your BR




var attachments = new GlideRecord('sys_attachment');


attachments.addQuery('table_sys_id',current.sys_id);


attachments.query();


var rowCount =   attachments.getRowCount();




and use rowCount in your If condition . if its more then 0 then it will help you   to apply conditions according to your requirement.



Thanks ,


Rohit


Hi how to check Row Count is getting changed or not. Please help even i have same kind of requirement.