Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Make checkbox true based on another form's field value

Savvy
Tera Contributor

Hi. I want to make a checkbox "check" true on the incident task form if the category of the incident is "Env" on the incident form.
If someone could help me how can I set a checkbox true based on another form's value.

5 REPLIES 5

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Savvy,

Create a onChange() script on field "Incident" on table "Incident Task" that calls Script Include to check incident's category.

1. onChange() client script

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

    var ajax = new GlideAjax('IncidentUtilClient');
    ajax.addParam('sysparm_name', 'checkCategory');
    ajax.addParam('sysparm_incident_id', newValue);
    ajax.addParam('sysparm_cat_name', catName);
    ajax.getXMLAnswer(function(answer) {
        alert(answer);
        if (answer.length > 0) {
            if (answer == 'true') {
                g_form.setValue('<field to check>', true);
            } else {
                g_form.setValue('<field to check>', false);
            }
        }
    });
}

Script Include

var IncidentUtilClient = Class.create();
IncidentUtilClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkCategory: function() {
        var incidentId = this.getParameter('sysparm_incident_id');
		var categoryName = this.getParameter('sysparm_cat_name');
        var grIncident = new GlideRecord('incident');
		grIncident.addQuery('sys_id', incidentId);
		grIncident.addQuery('category', categoryName);
		grIncident.query();
        if (grIncident.hasNext()) {
            return "true";
        }
		return "false";
    },
    type: 'IncidentUtilClient'
});

find_real_file.png