Update incident.state when attachment is added by someone from Watch list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 05:53 AM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 06:17 AM
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
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 07:17 AM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 07:21 AM
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
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 07:56 AM
Still doesn't work. Works only when caller inserts attachment. When someone from the watch list inserts an attachment, nothing happens.