Update incident.state when attachment is added by someone from Watch list

Nayara Araujo
Tera Contributor

HI All,

 

I want incident.state to be updated when an attachment/image is attached to the incident by someone from Watch list.

I have a business rule that changes the status to in progress when the caller adds an attachment and and it works well. But I need to put a condition so that it also changes the status if someone from the wacth list inserts an attachment.

I hope that someone can help me with this.

Thank you in advance.

 

Table: Attachment [sys_attachment]

When: After 

Inser
Condition: current.table_name == "incident"
Script:

var gr = new GlideRecord(current.table_name);
gr.addQuery('sys_id',current.table_sys_id);
gr.query();

while(gr.next())
{

if(gr.caller_id.user_name==current.sys_created_by)
{

gr.state =2;
gr.update();
}
}

 

when_to_run_br.pngscript_br_attachment.png

5 REPLIES 5

Hi,
I had a similar use case today as well.
The watch list returns a list of Sys ID's from the users. On the sys_attachment Table the user name is only stored as a string. So i tried the following:

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

	var gr = new GlideRecord(current.table_name);
	gr.addQuery('sys_id', current.table_sys_id);
	gr.query();
	var username = current.sys_created_by;
	var userGR = new GlideRecord('sys_user');
	userGR.get('user_name', username);
	var user_id = userGR.sys_id.toString();
	while(gr.next()){
		
		if(gr.caller_id.user_name==current.sys_created_by || gr.watch_list.toString().indexOf(user_id) !== -1){
			gr.state = 2;
			gr.update();
		}
	}

})(current, previous);

I hope this helps.