Set Impact based on service

menardJA
Tera Contributor

I have a requirement to have Impact on incidents set automatically based on the selected service then have a drop down where Help Desk can indicate how many users are impacted which would either lower or increase the impact based on the choice so if something has a default impact of 1 but is only affecting a single user it will drop to a 2.

 

I have created a Business Impact field on my business services and created a catalog client script that is supposed to read the value and then set the impact value but the impact never changes.

 

Has anyone ever done this before? Any tips or guides?

2 REPLIES 2

Shubham_Jain
Mega Sage
Mega Sage

@menardJA 

 

 write a onchange client script and Script include to achieve this,

Script Include (client callable checked)

getBusinessServicePriority : function()
{
var getBusiness = this.getParameter('sysparm_sys_id');
var sr = new GlideRecord('cmdb_ci_service');
sr.addQuery('sys_id',getBusiness);
sr.query();
if(sr.next())
{
return sr.busines_criticality.toString();
}
},

 

Client SCript onchange on Service field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var getServiceName = g_form.getValue('business_service');
var ga = new GlideAjax('demoAjax');
ga.addParam('sysparm_name', 'getBusinessServicePriority');
ga.addParam('sysparm_sys_id', getServiceName);
ga.getXML(serverResponse);

}
function serverResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == '2 - somewhat critical')
{
g_form.setValue('priority',1);
}

else if(answer == 'your value')
{
g_form.setValue('priority',2);
}
}

 

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


Hi @Shubham_Jain 

I tweaked the scripts slightly to fit what I had the variables as on my instance however the impact is not updating when I select a Service

Script include

var getBusinessServicePriority = Class.create();
getBusinessServicePriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   // Returns the numeric value (1/2/3) from u_business_impact on the Business Service
   getBusinessServicePriority: function () {
       var serviceSysId = this.getParameter('sysparm_sys_id');
       if (!serviceSysId) return '';
       var svc = new GlideRecord('cmdb_ci_service');
       if (svc.get(serviceSysId)) {
           // Return the VALUE (e.g., "1", "2", "3")
           return String(svc.getValue('u_business_impact') || '');
           // If you actually need the LABEL, switch to:
           // return String(svc.getDisplayValue('u_business_impact') || '');
       }
       return '';
   },
   type: 'getBusinessServicePriority'
});

Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || isTemplate || !newValue) return;
   var ga = new GlideAjax('getBusinessServicePriority');
   ga.addParam('sysparm_name', 'getBusinessServicePriority');
   ga.addParam('sysparm_sys_id', newValue);
   ga.getXMLAnswer(function(answer) {
       if (!answer) return;
       // If Script Include returned the numeric VALUE ("1","2","3"):
       var impactNum = parseInt(answer, 10);
       if (!isNaN(impactNum)) {
           // Incident.impact expects 1/2/3 by default (High/Medium/Low)
           g_form.setValue('impact', impactNum);
           return;
       }
       // If Script Include was changed to return the LABEL (e.g., "1 - High"):
       var match = (answer || '').match(/^(\d+)/);
       if (match) {
           g_form.setValue('impact', parseInt(match[1], 10));
       }
   });
}