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

Rahul Kumar17
Tera Guru

Hi,

 

You can do this by adding the following condition:

current.watch_list.toString().contains(gs.getUserID())

 

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 || current.watch_list.toString().contains(gs.getUserID())) {
        gr.state = 2;
        gr.update();
    }
}

 

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Hello @Rahul Kumar17 

 

Sorry for my ignorance. I tried this script but it still doesn't work. Works only when caller inserts attachment. When someone from the watch list inserts an attachment, nothing happens. Would there be any other way? Thank you in advance.

 

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 || current.watch_list.toString().contains(gs.getUserID())) {
gr.state = 2;
gr.update();
}
}

 

watchlist.script.pngwhen_to_run_br.png

 

can you try this

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

while (gr.next()) {
    var attachmentGr = new GlideRecord('sys_attachment');
    attachmentGr.addQuery('table_name', current.table_name);
    attachmentGr.addQuery('table_sys_id', current.table_sys_id);
    attachmentGr.query();

    var attachmentAdded = false;
    while (attachmentGr.next()) {
        if (attachmentGr.created_by == gs.getUserID()) {
            attachmentAdded = true;
            break;
        }
    }

    if (gr.caller_id.user_name == current.sys_created_by || (attachmentAdded && current.watch_list.toString().contains(gs.getUserID()))) {
        gr.state = 2;
        gr.update();
    }
}

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Still doesn't work. Works only when caller inserts attachment. When someone from the watch list inserts an attachment, nothing happens.