making CHECKBOX variables READONLY and MANDATORY NOT working

Pradeep67
Tera Contributor

HI, 

I hvae a onchange normal clientscript code which runs on sc_task when state changes. from the display BR i am taking the checkbox variables from the RITM and based on that i need to make the other set of checkboxes READONLY and MANDATORY. All the variables after submitting the request goes READONLY. 

MY code goes as below:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var st=g_form.getValue('state');
if(st=='3'||st=='4'||st=='7'){ // when state is complete/incomplete/skipped 
if(g_scratchpad.computer=="true"){
g_form.setMandatory('variables.received1',true);
g_form.setReadOnly('variables.received1',false);
}
if(g_scratchpad.headset=="true"){
g_form.setReadOnly('variables.received2',false);
g_form.setMandatory('variables.received2',true);
}
if(g_scratchpad.keyboard=="true"){
g_form.setReadOnly('variables.received3',false);
g_form.setMandatory('variables.received3',true);
}
}

This code is working fine, but when i test this, i observe that sc_task form gets saved if atleast one checkbox is true.

It is not maknig all the checkboxes mandatory, If one of the checkboxes is true form gets submitted.

Please assist me with this.

12 REPLIES 12

SanjivMeher
Kilo Patron
Kilo Patron

Correct the sequence and try

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var st=g_form.getValue('state');
if(st=='3'||st=='4'||st=='7'){ // when state is complete/incomplete/skipped 
if(g_scratchpad.computer=="true"){

g_form.setReadOnly('variables.received1',false);
g_form.setMandatory('variables.received1',true);

}
if(g_scratchpad.headset=="true"){
g_form.setReadOnly('variables.received2',false);
g_form.setMandatory('variables.received2',true);
}
if(g_scratchpad.keyboard=="true"){
g_form.setReadOnly('variables.received3',false);
g_form.setMandatory('variables.received3',true);
}
}


Please mark this response as correct or helpful if it assisted you with your question.

SanjivMeher
Kilo Patron
Kilo Patron

You can also create a UI policy for this in the Catalog Item itself  which is easier and Run it only on Requested Item and Task and uncheck the 'Applies on a Catalog Item view' checkbox.


Please mark this response as correct or helpful if it assisted you with your question.

i cannot get the state field from sc_task from catalog UI policy

checkbox variables are getting editable and mandatory as i needed, but when i make one of these checkboxes true leaving the rest unchecked, form gets submitted where it should not since they all are mandatory checkboxes 

Did you try this? Does it make the variables mandatory?

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var st=g_form.getValue('state');
if(st=='3'||st=='4'||st=='7'){ // when state is complete/incomplete/skipped 
if(g_scratchpad.computer=="true"){

g_form.setReadOnly('variables.received1',false);
g_form.setMandatory('variables.received1',true);

}
if(g_scratchpad.headset=="true"){
g_form.setReadOnly('variables.received2',false);
g_form.setMandatory('variables.received2',true);
}
if(g_scratchpad.keyboard=="true"){
g_form.setReadOnly('variables.received3',false);
g_form.setMandatory('variables.received3',true);
}
}


Please mark this response as correct or helpful if it assisted you with your question.