Auto group assignment

MK-p
Tera Contributor

I want to assign group automatically based on ci class selected on incident.

Should i use onchange client script or assignment rule and why?

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @MK-p ,

 

If you have few scenarios then i would recommend you to go through assignment rule and if list is big then i would suggest you to with client script.

 

For client script you need do the following for best practice.

1. Store data maping in custom table.

2. Call script include to get the group name based on ci class in your onchange client script.

 

For assignment rule you just need to do configuration like below.

RunjayPatel_0-1735644851447.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@MK-p You should use an Assignment rule as the value of assignment group can be populated without need of any scripting. On the other side any changes in the assignment group would require changes in the client script which will need some development effort.

Runjay Patel
Giga Sage

Hi @MK-p ,

 

If you have few scenarios then i would recommend you to go through assignment rule and if list is big then i would suggest you to with client script.

 

For client script you need do the following for best practice.

1. Store data maping in custom table.

2. Call script include to get the group name based on ci class in your onchange client script.

 

For assignment rule you just need to do configuration like below.

RunjayPatel_0-1735644851447.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Thanks @Runjay Patel I have more than 20 use case and in future it may increase. I would prefer to go with storing it in custom table so that business can add in future as well.

@MK-p 

remember custom table has cost involved with them.

why not use system property and store the mapping in JSON format? Admins can update it going forward in future

then use before insert BR and set the group

System property of type string with value like this( class name and group sysId)

{
  "cmdb_ci_computer":"Group ABC SysId",
  "cmdb_ci_linux":"Group DEF SysId"
}

then in before insert BR use this

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

    // Add your code here
    var jsonValue = gs.getProperty('propertyName');
    var parsedData = JSON.parse(jsonValue);
    current.assignment_group = parsedData[current.cmdb_ci.sys_class_name];

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader