Make check box unvisible using onChange client script

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.

 

ShirSharvit_0-1705942480202.png

The code:

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

    if (control == 'assignment_group') {

        var assignmentGroupType = g_form.getDisplayValue('assignment_group.type');


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

            g_form.setValue('u_false_transfer', false);
        }
    }
}

 

Can someone please help me fix it

Thanks, Shir

 

4 REPLIES 4

Aniket Chavan
Tera Sage
Tera Sage

Hello @Shir Sharvit ,

Please give a try to the script below and let me know how it works for you.

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

    if (control == 'assignment_group') {

        var assignmentGroupType = g_form.getDisplayValue('assignment_group.type');

        if (assignmentGroupType !== 'itil') {
            g_form.setDisplay('u_false_transfer', true); // Show the checkbox
        } else {
            g_form.setDisplay('u_false_transfer', false); // Hide the checkbox
            g_form.setValue('u_false_transfer', false);
        }
    }
}

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

This code not working

Hello @Shir Sharvit ,

Lets try to debug the code with added logs 

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

    if (control == 'assignment_group') {
        var assignmentGroupType = g_form.getDisplayValue('assignment_group.type');

        if (assignmentGroupType !== 'itil') {
            // Show the checkbox
            g_form.setDisplay('u_false_transfer', true);
            // Add an informational message
            g_form.addInfoMessage('u_false_transfer is visible because Assignment Group type is not itil.');
        } else {
            // Hide the checkbox
            g_form.setDisplay('u_false_transfer', false);
            g_form.setValue('u_false_transfer', false);
            // Add an informational message
            g_form.addInfoMessage('u_false_transfer is hidden because Assignment Group type is itil.');
        }
    }
}

Adrian Ubeda
Mega Sage
Mega Sage

Hello Shir, 

You can achieve that using UI Policies, there's an option called 'onLoad' in advanced view, and it will applies when loads the form and also changes the value:

AdrianUbeda_0-1705943429478.png

 

 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆