BR to check if an attachment is added to an INC

dagarson
Tera Guru

Hello Im looking for a business rule I can run to check and see if an attachment is added to the INC ticket, and if one is update the state to work in progress.

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

Since you need the BR to trigger when an attachment is added to the incident (which does not, by itself, trigger as an update to the Incident) you would want to run your BR off of the sys_attachment table. 

Table: Attachment [sys_attachment]

Advanced: checked

When to Run: After, Insert. 

Condition: Table name is incident

Script: (update state value as needed)

(function executeRule(current, previous /*null when async*/) {

	
	var inc = new GlideRecord('incident');
	inc.get(current.table_sys_id);
	inc.state=2;
	inc.update();
	
	

})(current, previous);

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use this in the BR

if(current.hasAttachments()){

// update state to in progress

}

Regards
Ankur

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

Michael Jones -
Giga Sage

Since you need the BR to trigger when an attachment is added to the incident (which does not, by itself, trigger as an update to the Incident) you would want to run your BR off of the sys_attachment table. 

Table: Attachment [sys_attachment]

Advanced: checked

When to Run: After, Insert. 

Condition: Table name is incident

Script: (update state value as needed)

(function executeRule(current, previous /*null when async*/) {

	
	var inc = new GlideRecord('incident');
	inc.get(current.table_sys_id);
	inc.state=2;
	inc.update();
	
	

})(current, previous);

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Thank you so much this was just the start I needed

Rajesh Chopade
Kilo Expert

Hi ,

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 ,