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

Samaksh Wani
Giga Sage
Giga Sage

Hello @WazzaJC 

 

 

var service = g_form.getValue('service');

if(service == 'most critical'){
g_form.setValue('urgency', 'high');
}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

 

Hi Samaksh,

 

Thanks for your quick reply, unfortunately this doesn't work / is not the correct solution based on what I have asked. Have you tried configuring this in your PDI to confirm it all works ?

 

I need it to work based on the 'Business Criticality' level that is associated with the 'Service' that is selected.

 

Thanks.

Hello @WazzaJC 

 

You need to write a Display Business rule for this case :-

 

 

 

if(current.service.business_service == 'most critical'){
current.urgency = 'high';
}

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

Nitesh A
Tera Expert

Hello @WazzaJC 

 

Below logic you can use:

in OnChange Client script for Service

1. Get the value[sys_id]

2. Call Script Include using GlideAjax

3. Pass the sys_id of service as parameter

4. In Script include read the sys_id and get the value of Business Criticality and return that value

5. In Client script check the value returned from script include

6. Add some conditions and check and set the urgency accordingly.

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Nitesh