Update incident.state when attachment is added by caller

soren_bogvad
Tera Contributor

HI All,

I want incident.state to be updated when an attachment/image is attached to the incident by the caller or opened_by.

Scenario:

In some cases we request the caller/opened_by to provide additional information in order to resolve an incident.

As we awaits their feedback the incident.state is set to ‘pending user’.

If the caller responds only by uploading a attachment/image from the Serviceportal without adding a comment the incident.state is not updated to ‘updated by caller’ and we don’t see it in our incident list.

I have succeeded in changing the state in general with the following business rule but my goal is that It only happens when it is done by the caller or opened_by.

Business rule: 'Update incident.state when attachment is added by caller'
Table: Attachment [sys_attachment]
Condition: current.table_name == "incident"
Script:

updateRecordForAttachment();

function updateRecordForAttachment(){

var gr = new GlideRecord(current.table_name);

if(gr.get(current.table_sys_id)){

gr.state = '99';  // value ’99’ is incident.state=updated by caller

gr.update();

}

}

--

I hope that someone can help me with this.

Thank you in advance.

1 ACCEPTED SOLUTION

Varsha21
Giga Guru

Hi,

//gs.log(current.table_name+"  "+current.table_sys_id+"  jjj"+current.sys_created_by+"  ");
var gr = new GlideRecord(current.table_name);
	gr.addQuery('sys_id',current.table_sys_id);
	gr.query();
	//gs.log("test+"+gr.getRowCount());
	while(gr.next())
		{
			//gs.log(gr.caller_id.user_name+"  "+current.sys_created_by+"  kkkk");
			if(gr.caller_id.user_name==current.sys_created_by || gr.opened_by.user_name==current.sys_created_by)
				{
					//gs.log(gr.getValue('state')+"1");
			gr.state =2;
			gr.update();
				}
		}

use the same script ,worked for me.

remove all comment code used for testing,

use your state value proper , my incident database value in progress is 2.

 

varsha

View solution in original post

5 REPLIES 5

Hi,

Did you try this code?