How to Set the Incident Assignment Logic based on the CI field groups

nikhitha24
Tera Guru

Hi Team,

 

Can anyone please help me on the below query how can we achieve this in ServiceNow.

 

In Incident if i selected ci is related to Application server class in that i have 3 Custom fields and those are reference field to the group table. For example if i selected ci as server it should check weather field1 is having group or not if group is there the incident should assign to that group, if not i should check second field like this i need to set a auto assignment logic for incident.

Thank You.

 

1 ACCEPTED SOLUTION

Here is the corrected code.

Make it run in BUsiness rule After Incident is inserted. Basically on table : incident

 

(function executeRule(current, previous) {
 
 if (current.cmdb_ci !='' && current.cmdb_ci.sys_class_name='cmdb_ci_service_auto') {
    var groupField1 = current.cmdb_ci.u_reference_3;
    var groupField2 = current.cmdb_ci.u_reference_4;
    var groupField3 = current.cmdb_ci.u_reference_5;

    if (isGroupValid(groupField1)) {
      current.assignment_group = groupField1;
    }
    else if (isGroupValid(groupField2)) {
      current.assignment_group = groupField2;
    }
    else if (isGroupValid(groupField3)) {
      current.assignment_group = groupField3;
    }
	
	current.update();
  }
})(current, previous);

function isGroupValid(group) {
  if (group) {
    var groupGR = new GlideRecord('sys_user_group');
    if (groupGR.get(group)) {
      return true;
    }
  }
  return false;
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

4 REPLIES 4

sushantmalsure
Mega Sage
Mega Sage

Hi @nikhitha24 

When does it needs to assigned to said group? when incident is created or anytime during incident lifecycle like if CI changed after sometime on incident then new AG should be added as per CI?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi @sushantmalsure 

When the incident record is created from a record producer i have a variable to select the CI based on that CI it need to be assigned to that group.

I have written Before Business rule when the record is insert and the table is record producer for this but it is not working.

Please refer the code below.

(function executeRule(current, previous) {
  if (isApplicationServerClass(current.cmdb_ci)) {
    var groupField1 = current.variables.u_reference_3;
    var groupField2 = current.variables.u_reference_4;
    var groupField3 = current.variables.u_reference_5;

    if (isGroupValid(groupField1)) {
      current.assignment_group = groupField1;
    }
    else if (isGroupValid(groupField2)) {
      current.assignment_group = groupField2;
    }
    else if (isGroupValid(groupField3)) {
      current.assignment_group = groupField3;
    }
  }
})(current, previous);
function isApplicationServicesClass(ci) {
  var applicationServicesClass = "Application Services";
  return (ci && sys_class_name == applicationServicesClass);
}
function isGroupValid(group) {
  if (group) {
    var groupGR = new GlideRecord('sys_user_group');
    if (groupGR.get(group)) {
      return true;
    }
  }
  return false;
}


Here is the corrected code.

Make it run in BUsiness rule After Incident is inserted. Basically on table : incident

 

(function executeRule(current, previous) {
 
 if (current.cmdb_ci !='' && current.cmdb_ci.sys_class_name='cmdb_ci_service_auto') {
    var groupField1 = current.cmdb_ci.u_reference_3;
    var groupField2 = current.cmdb_ci.u_reference_4;
    var groupField3 = current.cmdb_ci.u_reference_5;

    if (isGroupValid(groupField1)) {
      current.assignment_group = groupField1;
    }
    else if (isGroupValid(groupField2)) {
      current.assignment_group = groupField2;
    }
    else if (isGroupValid(groupField3)) {
      current.assignment_group = groupField3;
    }
	
	current.update();
  }
})(current, previous);

function isGroupValid(group) {
  if (group) {
    var groupGR = new GlideRecord('sys_user_group');
    if (groupGR.get(group)) {
      return true;
    }
  }
  return false;
}
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi @sushantmalsure 

Thank you Sushantmalsure, It is working now.