How can I use onChange Client Script to set Incident Urgency based on Service Business Criticality

WazzaJC
Tera Expert

How can I use onChange Client Script to set Incident Urgency based on Service Business Criticality

 

Hi Guys,

 

I would greatly appreciate help/guidance on the correct onChange Client Script to use for achieving the following please:

 

On my 'Incident' form, I want to auto-populate the 'Urgency' field based on the 'Business Criticality' related to the Service (business_service) that is selected on the form, by the agent/user.

 

Every 'Service' (business_service) has an associated Business Criticality eg '1 - most critical', '2 - somewhat critical' etc.

 

I want the onChange client script to be based on the Field 'Service' so that when the selected 'Service' changes, the value in the 'Urgency' field will change and this Urgency value will be based on the Business Criticality level associated to the Service.

 

EG. If a 'Service' has a Business Criticality = '1 - most critical', then Urgency will auto-set to = '1 - High'.

 

Many thanks for any advice on the script to use.

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

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

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);
}
}

HarishKM_1-1690272276042.png

 

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();
}

},

HarishKM_0-1690272253933.png

 

Regards
Harish

View solution in original post

6 REPLIES 6

Harish KM
Kilo Patron
Kilo Patron

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

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);
}
}

HarishKM_1-1690272276042.png

 

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();
}

},

HarishKM_0-1690272253933.png

 

Regards
Harish

Many thanks Harish, this is great and is the solution I was looking for.

 

Thanks very much for your help, much appreciated.