The CreatorCon Call for Content is officially open! Get started here.

How to make checkboxes readonly and checked as true on catalog item?

Kotaiah
Kilo Guru

Hi All,

I have catalog item with two 'multiple choice' variables named 'Group Type & Level of permission'.

find_real_file.pngfind_real_file.png

Group type check boxes are grayed out based on variable.

Here my requirement is when 'S-Security Incident Response' is checked and sub type of the group is one of 'level1_sir_admin or level2_security_assignment or level3_readonly' then we need to make the level1,level2 and level3 checkboxes readonly false else need to make readonly true.

to achieve the same i have written one onChange client script.

================================================

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

var reqType = g_form.getValue('request_type');

var groupSubType = g_form.getValue('existing_group');

if(reqType == 'Modify Group' && newValue == 'true'){

alert('@123 inside');

var ga = new GlideAjax('gettingsubtypeofgroup');

ga.addParam('sysparm_name','groupSubType');

ga.addParam('sysparm_group_sys_id',groupSubType);

ga.getXML(GetSubTypeofGroup);

}

}

function GetSubTypeofGroup(response){

var subtype = response.responseXML.documentElement.getAttribute("answer");

alert(subtype);

if(subtype == 'level1_sir_admin'){

alert('@123 inside level of authorization:'+subtype);

g_form.setReadOnly('level_of_permission', 'false');

}else{

alert('@123 inside else level of authorization');

g_form.setReadOnly('level_of_permission', 'true');

}

/*g_form.setValue('level1_sir_admin', 'true');

g_form.setValue('level2_security_assignment', 'false');

g_form.setValue('level3_readonly', 'false');

}else if(subtype == 'level2_security_assignment'){

alert('@123 inside level of authorization:'+subtype);

g_form.setReadOnly('level_of_permission', 'false');

g_form.setValue('level2_security_assignment', 'true');

g_form.setValue('level1_sir_admin', 'false');

g_form.setValue('level3_readonly', 'false');

}else if(subtype == 'level3_readonly'){

alert('@123 inside level of authorization:'+subtype);

g_form.setReadOnly('level_of_permission', 'false');

g_form.setValue('level3_readonly', 'true');

g_form.setValue('level1_sir_admin', 'false');

g_form.setValue('level2_security_assignment', 'false');

}*/

}

=======================

But changes are not reflcating properly, can you please help me.

Regards,

Kotaiah Sadari

4 REPLIES 4

Geoffrey2
ServiceNow Employee
ServiceNow Employee

The second argument for g_form.setReadOnly() should be a boolean.   You have strings.



This:


g_form.setReadOnly('level_of_permission', false);



NOT this:


g_form.setReadOnly('level_of_permission', 'false');


Hi Geoffrey,



I changes as boolean now also not working.



Regards,


Kotaiah Sadari


Geoffrey2
ServiceNow Employee
ServiceNow Employee

I couldn't tell you what else is wrong without more information.


Are you seeing all of the alert popups?


Are you getting a response from the GlideAjax?


Are there any errors in the console log?


I don't understand why your "Multiple choice" variable is rendering as checkboxes when I see radio buttons. There must be more to it than what you have described.


I am not sure that OnChange script will work on your Checkbox to make it checked or Read-only.


You can make it checked onChange but it also remain in background.