If Incident ticket has an attachment, make a field true.

prabhmeet
Giga Expert

Hi,

I want that if incident has an attachment attached the field should show as true, otherwise false.

I am new to servicenow and not good at coding but I have written the following before business rule code on incident table.

Please also let me know Client Script is better or Business Rule.

Below mentioned code is not working. Can someone please help me with the mistake?

 var rec = new GlideRecord('incident');
rec.addQuery('sys_id', current.incident_sys_id);
rec.query();
if(rec.next()){
if(rec.hasAttachments()){
rec.u_attachment= true;
}
}

 

Thanks

1 ACCEPTED SOLUTION

Hi ,

I tried the following code in a before insert, update BR in my dev instance, which is working fine,

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

	if(current.hasAttachments()){		
	current.setValue("u_has_attachment","true");
					 gs.addInfoMessage("Attachment Present");
	}
	else if(!current.hasAttachments())
		{
	        current.setValue("u_has_attachment","false");
					 gs.addInfoMessage("Attachment Absent");
			
		}
	
	

Regards,
Ajay

View solution in original post

28 REPLIES 28

To update, you have to change some field on your incident form and then save the record.

Regards,
Ajay

Thanks Ajay.

Hi Prabhmeet,

Please mark the answer as correct and close the thread.

Regards,
Ajay

is there any way to avoid having to change a field, that when the attachment is added the box automatically checks off?