setdisplay true or false not working in catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 09:52 AM
Hi All,
I created a on change catalog client script as below:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.setDisplay('dp_internal_or_external', false);
g_form.setMandatory('dp_internal_or_external', false);
g_form.setDisplay('dp_client_name_existing', false);
g_form.setMandatory('dp_client_name_existing', false);
g_form.setDisplay('dp_client_name', false);
g_form.setMandatory('dp_client_name', false);
g_form.setDisplay('dp_technical_account_manager', false);
g_form.setMandatory('dp_technical_account_manager', false);
g_form.setDisplay('dp_environment', false);
g_form.setMandatory('dp_environment', false);
g_form.setDisplay('dp_client_name_abbreviation', false);
g_form.setDisplay('dp_client_solution_name_abbreviation', false);
g_form.setDisplay('dp_authorized_approver_1_last', false);
g_form.setDisplay('dp_authorized_approver_3', false);
g_form.setDisplay('dp_authorized_approver_2_email', false);
g_form.setDisplay('dp_authorized_approver_2_first', false);
g_form.setDisplay('dp_authorized_approver_2', false);
g_form.setDisplay('dp_authorized_approver_3_last', false);
g_form.setDisplay('dp_authorized_approver_1_email', false);
g_form.setDisplay('dp_authorized_approver_3_email', false);
g_form.setDisplay('dp_authorized_approver_1_first', false);
g_form.setDisplay('dp_authorized_approver_3_first', false);
g_form.setDisplay('dp_authorized_approver_2_last', false);
g_form.setDisplay('dp_authorized_approver_1', false);
g_form.setDisplay('dp_authorized_approvers_external', false);
//g_form.setDisplay('vs_dp_authorized_approvers_external', false);
g_form.setMandatory('dp_authorized_approver_1_first', false);
g_form.setMandatory('dp_authorized_approver_1_email', false);
g_form.setMandatory('dp_authorized_approver_1_last', false);
g_form.setDisplay('dp__business', false);
g_form.setMandatory('dp__business', false);
g_form.setDisplay('dp__segment', false);
g_form.setMandatory('dp__segment', false);
g_form.setDisplay('dp_would_you_like_to_request_a_billing_id', false);
g_form.setMandatory('dp_would_you_like_to_request_a_billing_id', false);
g_form.setDisplay('dp_authorized_approvers', false);
g_form.setDisplay('dp_authorized_approvers_internal', false);
g_form.setMandatory('dp_authorized_approvers_internal', false);
g_form.setDisplay('program_product_name', false);
g_form.setMandatory('program_product_name', false);
return;
}
/*if (newValue != '') {
g_form.setDisplay('dp_client_name_existing', false);
g_form.setMandatory('dp_client_name_existing', false);
}*/
alert(newValue);
var getnewcl = g_form.getValue('dp_new_or_existing_client');
if (getnewcl == "New Client") {
//
if (newValue == "u_internal_y") {
g_form.setDisplay('dp_client_name', true);
g_form.setMandatory('dp_client_name', true);
g_form.setDisplay('dp_client_name_abbreviation', true);
g_form.setDisplay('dp__business', true);
g_form.setMandatory('dp__business', true);
g_form.setDisplay('dp__segment', true);
g_form.setMandatory('dp__segment', true);
g_form.setMandatory('dp_environment', true);
g_form.setDisplay('dp_environment', true);
g_form.setDisplay('program_product_name', true);
g_form.setMandatory('program_product_name', true);
g_form.setDisplay('dp_client_solution_name_abbreviation', true);
g_form.setDisplay('dp_technical_account_manager', true);
g_form.setMandatory('dp_technical_account_manager', true);
g_form.setDisplay('dp_would_you_like_to_request_a_billing_id', true);
g_form.setMandatory('dp_would_you_like_to_request_a_billing_id', true);
//
g_form.setDisplay('dp_authorized_approvers', true);
g_form.setDisplay('dp_authorized_approvers_internal', true);
g_form.setMandatory('dp_authorized_approvers_internal', true);
//
g_form.setDisplay('dp_authorized_approver_1_last', false);
g_form.setDisplay('dp_authorized_approver_3', false);
g_form.setDisplay('dp_authorized_approver_2_email', false);
g_form.setDisplay('dp_authorized_approver_2_first', false);
g_form.setDisplay('dp_authorized_approver_2', false);
g_form.setDisplay('dp_authorized_approver_3_last', false);
g_form.setDisplay('dp_authorized_approver_1_email', false);
g_form.setDisplay('dp_authorized_approver_3_email', false);
g_form.setDisplay('dp_authorized_approver_1_first', false);
g_form.setDisplay('dp_authorized_approver_3_first', false);
g_form.setDisplay('dp_authorized_approver_2_last', false);
g_form.setDisplay('dp_authorized_approver_1', false);
g_form.setDisplay('dp_authorized_approvers_external', false);
g_form.setMandatory('dp_authorized_approver_1_first', false);
g_form.setMandatory('dp_authorized_approver_1_email', false);
g_form.setMandatory('dp_authorized_approver_1_last', false);
}
if (newValue == "u_external_y") {
//
g_form.setDisplay('dp__business', false);
g_form.setMandatory('dp__business', false);
g_form.setDisplay('dp__segment', false);
g_form.setMandatory('dp__segment', false);
g_form.setDisplay('dp_client_name', true);
g_form.setMandatory('dp_client_name', true);
g_form.setDisplay('dp_client_name_abbreviation', true);
g_form.setMandatory('dp_environment', true);
g_form.setDisplay('dp_environment', true);
g_form.setDisplay('program_product_name', true);
g_form.setMandatory('program_product_name', true);
g_form.setDisplay('dp_client_solution_name_abbreviation', true);
g_form.setDisplay('dp_technical_account_manager', true);
g_form.setMandatory('dp_technical_account_manager', true);
g_form.setDisplay('dp_would_you_like_to_request_a_billing_id', true);
g_form.setMandatory('dp_would_you_like_to_request_a_billing_id', true);
g_form.setDisplay('dp_authorized_approver_1_last', true);
g_form.setMandatory('dp_authorized_approver_1_last', true);
g_form.setDisplay('dp_authorized_approver_3', true);
g_form.setDisplay('dp_authorized_approver_2_email', true);
g_form.setDisplay('dp_authorized_approver_2_first', true);
g_form.setDisplay('dp_authorized_approver_2', true);
g_form.setDisplay('dp_authorized_approver_3_last', true);
g_form.setDisplay('dp_authorized_approver_1_email', true);
g_form.setMandatory('dp_authorized_approver_1_email', true);
g_form.setDisplay('dp_authorized_approver_3_email', true);
g_form.setDisplay('dp_authorized_approver_1_first', true);
g_form.setMandatory('dp_authorized_approver_1_first', true);
g_form.setDisplay('dp_authorized_approver_3_first', true);
g_form.setDisplay('dp_authorized_approver_2_last', true);
g_form.setDisplay('dp_authorized_approver_1', true);
g_form.setDisplay('dp_authorized_approvers_external', true);
g_form.setDisplay('vs_dp_authorized_approvers_external', true);
g_form.setDisplay('dp_authorized_approvers', false);
g_form.setDisplay('dp_authorized_approvers_internal', false);
g_form.setMandatory('dp_authorized_approvers_internal', false);
}
}
}
while the alert shows right values 2 variables are still visible and I tried everything.
g_form.setDisplay('dp__business', false);
g_form.setMandatory('dp__business', false);
g_form.setDisplay('dp__segment', false);
g_form.setMandatory('dp__segment', false);
These 4 should be false for the cond external.
PS: I checked the variable and is not mandate but there is another on change client script
Looking for help
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 10:16 AM
In all cases you should setMandatory to false before setDisplay to false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 06:52 PM
Hi @DB1 ,
setDisplay will work if filed is non mandatory, and if field is mandatory and you are applying setDisplay false then first you have to make that field non mandatory with setMandatory false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 08:23 PM
As others have mentioned if there is another script which is making it mandatory, you cannot hide
1st make it non mandatory and then hide
Any other UI policy is conflicting?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader