Task

XYD23
Tera Contributor

Requirement is:

In incident form, when priority changes to 1-critical, the description should set to "this is a critical incident".

 

 

1 ACCEPTED SOLUTION

Rahul Talreja
Mega Sage
Mega Sage

Hi @XYD23 ,
As per your requirment using both SI and CS
Try this:
Client Script

 

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

    if (newValue == 1) { // Assuming '1' is the value for Critical priority
        var gr = new GlideAjax('UpdateIncidentPriority');
        gr.addParam('sysparm_name', 'updateDescription');
        gr.getXML(onComplete);

function onComplete(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var result = JSON.parse(answer);
			g_form.setValue('description',result.desc);
        }
    }

}

 

Script Include: (Name - UpdateIncidentPriority, Make it client callable)

 

var UpdateIncidentPriority = Class.create();
UpdateIncidentPriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    updateDescription: function() {
        var obj = {};
		obj.desc= "This is critical Incident";
		return JSON.stringify(obj);

    },
    type: 'UpdateIncidentPriority'
});

 

 Please replace '1' with the actual value for Critical priority in your ServiceNow instance.

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi @XYD23 ,

 

 Create onChange - client script on Priority field:

JackTKQ_0-1701337212507.png

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

    if (newValue != oldValue && newValue == 1) {
        g_form.setValue('description', 'this is a critical incident');
    }

}

Rahul Talreja
Mega Sage
Mega Sage

Hi @XYD23 ,
As per your requirment using both SI and CS
Try this:
Client Script

 

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

    if (newValue == 1) { // Assuming '1' is the value for Critical priority
        var gr = new GlideAjax('UpdateIncidentPriority');
        gr.addParam('sysparm_name', 'updateDescription');
        gr.getXML(onComplete);

function onComplete(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var result = JSON.parse(answer);
			g_form.setValue('description',result.desc);
        }
    }

}

 

Script Include: (Name - UpdateIncidentPriority, Make it client callable)

 

var UpdateIncidentPriority = Class.create();
UpdateIncidentPriority.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    updateDescription: function() {
        var obj = {};
		obj.desc= "This is critical Incident";
		return JSON.stringify(obj);

    },
    type: 'UpdateIncidentPriority'
});

 

 Please replace '1' with the actual value for Critical priority in your ServiceNow instance.

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Prince Arora
Tera Sage
Tera Sage

@XYD23 

 

You don't need to make GlideAjax call for this as the requirement can handle using client script only

You can write an onChange client script on priority field as mention below code:

 

if(newValue == 1){
 g_form.setValue('description',"This is a critical incident")
}else{
  g_form.clearValue("description");
}

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.