Make check box unvisible using onChange client script and script include

Shir Sharvit
Tera Contributor

Hey

I created a check box on incident form in SOW called u_false_transfer.

I need this check box to be visible only if Assignment group type is not 'itil' .

I tried to use UI POLICIES but it workes only after saving the record.

Now I want to write ONchange client script with GlideAjax and Script include.

 

Script include:

ShirSharvit_0-1706006822241.png

code:

var GETgrouptype = Class.create();
GETgrouptype.prototype = {
    initialize: function() {},

    getAssignmentGroupType: function() {
        var groupSysId = this.getParameter('sysparm_groupSysId');
        var groupType = '';

        var gr = new GlideRecord('sys_user_group');

        if (gr.get(groupSysId)) {
            groupType = gr.getValue('type');
        }

        return groupType;
    },

    type: 'GETgrouptype'
};
 
and client script onChange:
ShirSharvit_1-1706006908125.png

code:

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

    var ajax = new GlideAjax('GETgrouptype');
    ajax.addParam('sysparm_name', 'getAssignmentGroupType');
    ajax.addParam('sysparm_groupSysId', newValue);
    ajax.getXML(onAjaxComplete);

    function onAjaxComplete(response) {
        if (response) {
            var assignmentGroupType = response.responseXML.documentElement.getAttribute('answer');

            if (assignmentGroupType !== 'itil') {
                g_form.setDisplay('u_false_transfer', true);
            } else {
                g_form.setDisplay('u_false_transfer', false);
            }
        }
    }
}
 
 

Can someone please help me fix it

Thanks, Shir

3 REPLIES 3

Kartik Sethi
Tera Guru
Tera Guru

Hi @Shir Sharvit 

In this case GlideAjax and Client Callable Script Include will not work for you as it will be an async call and changes will not reflect immediately after making a change on the Assignment Group.

 

Please share the UI Policy screenshot that you have created earlier.

 

Best regards,

Kartik Sethi

Ct111
Giga Sage

 

your code inside script include is wrong.

 

Take below two examples for reference

1.)  Solved: Check group type of a group - ServiceNow Community

 

I need the script include to return the group type of the assignment group and then check this conditions

ShirSharvit_0-1706008387921.png