The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How do i hide variables on a catalog item depending on a selection of another variable.

abcmh
Giga Contributor

I have a Service Catalog item that i am working on . I am adding variables to this item which are checkboxes, radio buttons, multivalue drop down selections, text values, date items etc.

If i select a particular check box like "New Contract" , i need to display a couple of date variables and a comments variable.

What is the best way to achieve this ? Any suggestions?

Thanks,

31 REPLIES 31

abcmh
Giga Contributor

Hi Balaji,



This is my script in the onChange event of the item. But no luck. What am i doing wrong?



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


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


  g_form.setDisplay('CRE_ContractStartDt',false);


  g_form.setDisplay('CRE_NewContractEnd',false);


  g_form.setDisplay('CRE_BC_Description',false);


  g_form.setDisplay('CRE_AddCmts',false);


  return;


  }


  if (newValue == 'true'){


  g_form.setDisplay('CRE_ContractStartDt',true);


  g_form.setDisplay('CRE_NewContractEnd',true);


  g_form.setDisplay('CRE_BC_Description',true);


  g_form.setDisplay('CRE_AddCmts',true);


  }


  else{


  g_form.setDisplay('CRE_ContractStartDt',false);


  g_form.setDisplay('CRE_NewContractEnd',false);


  g_form.setDisplay('CRE_BC_Description',false);


  g_form.setDisplay('CRE_AddCmts',false);


  }


}


Hi Amol,



The problem is not with the script, because of variables mandatory at dictionary level. Because of that issue variables are not hiding for your scenario.


To workaround do like this way,


1) remove the mandatory of all fields.


go to configure dictionary of the "new contract date, end date and description" uncheck the mandatory false.


find_real_file.png


2) Now write a UI Policy or client script, when ever "new contact" is true, make visible and mandatory


find_real_file.png


if you want to go with client script:



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


  if (isLoading ) {


g_form.setMandatory('CRE_ContractStartDt',false);


  g_form.setDisplay('CRE_ContractStartDt',false);


  g_form.setMandatory('CRE_NewContractEnd',false);


  g_form.setDisplay('CRE_NewContractEnd',false);


  g_form.setMandatory('CRE_BC_Description',false);


  g_form.setDisplay('CRE_BC_Description',false);


  g_form.setDisplay('CRE_AddCmts',false);


  return;


  }


  if (newValue == 'true'){


  g_form.setDisplay('CRE_ContractStartDt',true);


  g_form.setMandatory('CRE_ContractStartDt',true);


  g_form.setDisplay('CRE_NewContractEnd',true);


  g_form.setMandatory('CRE_NewContractEnd',true);


  g_form.setDisplay('CRE_BC_Description',true);


  g_form.setMandatory('CRE_BC_Description',true);


  g_form.setDisplay('CRE_AddCmts',true);


  }


  else{


  g_form.setMandatory('CRE_ContractStartDt',false);


  g_form.setDisplay('CRE_ContractStartDt',false);


  g_form.setMandatory('CRE_NewContractEnd',false);


  g_form.setDisplay('CRE_NewContractEnd',false);


  g_form.setMandatory('CRE_BC_Description',false);


  g_form.setDisplay('CRE_BC_Description',false);


  g_form.setDisplay('CRE_AddCmts',false);


  }


}


abcmh
Giga Contributor

Tried this too. No luck. Haven't done the updated script yet. I am no able to understand what is wrong with this. I have tried everything but haven't been able to make it work.


Did you removed mandatory at the dictionary level?



If you are doing this one in your personal instance, share your instance name and credentials. I will look at once.


reginabautista
Kilo Sage

I think you ened to change this line from



  if (newValue == 'true'){



to


  if (newValue == true){