Add CI SupportGroup to the watchlist automatically when a CI is selected

carlh
Kilo Guru

Hi All,

We have a scenario where some of our app owners are going to need to be aware of incidents.   They don't work the incidents so we don't want to assign them and consume a license.   We do need to give them access to view the incidents that come in about their area though.

When I select a configuration item, the Owner and Support group are also shown on my form.   Based on the Configuration Item selected on the incident, I'd like to add the Owner and Support Group members to the watch list.

Can anyone help me with a script to add a group's members to the watchlist of an incident on insert or maybe when a Boolean field is set to true?

Thanks,

Carl

1 ACCEPTED SOLUTION

curtisr
Kilo Expert

You could create a business rule that adds the owner and group members to the watch list when the incident is created and the values are present on the CI. Haven't tested this specifically, but something similar has worked for me.



Create new business rule: Add CI Owner to watch list


Table: Incident [incident]



When: before


Insert: True


Script:


//Add opened by to the watch list on the requested item if different from the requested for


addToWatchList();


function addToWatchList() {



//get CI owner and ad to watch list


current.watch_list += current.cmdb_ci.owner;



//get group members


var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group',current.cmdb_ci.support_group);


gr.query();


while(gr.next())


  {


              var user =(','+ gr.user);


              current.watch_list += user;


      }


}


View solution in original post

10 REPLIES 10

Sorry I thought I'd sent this reply.



We were able to figure out that we had the wrong field name



it's CMDB_CI.Owned_By not .Owner



So you got it right but I gave the wrong field or didn't pay attention.



Thanks so much.   This has been very helpful!!!!!


Awesome! Thanks for the update.


Hello,



We've been using this script for a while now and it works but it's adding the owner and group every time the record is updated.



I only need them added to the watchlist once.   Is there something I can do to avoid this?



Thanks in advance.



Carl


We have it set before insert, so it won't try to re-add them again on update. Are you running this on before update as well as insert?   Pretty sure you could script a check to see if they are already in the watch list and add if not, otherwise skip.


Thanks for replying. Yes I have this on insert and update.



On Insert, if contact type is phone, it would be on submit but if it came in via self service, it would need to be properly categorized first in which case it would be on update.



I have attached screenshots of the script I am using incase something got changed.