onChange Client Scripts execute script logic when a particular field’s value changes. Use onChange Client Scripts to respond to field values of interest and to modify another field’s value or attributes. For example, if the State field’s value changes to Closed Complete, generate an alert and make the Description field mandatory.
Requirement: If state is in progress show CI field visible and mandatory & if state is onHold Service field visible and mandatory.
OnLoad & OnChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { var s = g_form.getValue('state'); if (s == 2) { g_form.setDisplay('cmdb_ci', true); g_form.setDisplay('business_service', false); g_form.setMandatory('cmdb_ci', true); } else if (s == 3) { g_form.setDisplay('cmdb_ci', false); g_form.setDisplay('business_service', true); g_form.setMandatory('business_service', true); } return; } //Type appropriate comment here, and begin script below var s = newValue; if (s == 2) { g_form.setDisplay('cmdb_ci', true); g_form.setDisplay('business_service', false); g_form.setMandatory('cmdb_ci', true); g_form.setMandatory('business_service', false); } else if (s == 3) { g_form.setDisplay('cmdb_ci', false); g_form.setDisplay('business_service', true); g_form.setMandatory('business_service', true); g_form.setMandatory('cmdb_ci', false); } }
OnLoad & OnChange Client Script should work together & after the code optimization
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (newValue === '') { return; } //Type appropriate comment here, and begin script below var s = newValue; if (s == 2) { g_form.setDisplay('cmdb_ci', true); g_form.setDisplay('business_service', false); g_form.setMandatory('cmdb_ci', true); g_form.setMandatory('business_service', false); } else if (s == 3) { g_form.setDisplay('cmdb_ci', false); g_form.setDisplay('business_service', true); g_form.setMandatory('business_service', true); g_form.setMandatory('cmdb_ci', false); } }
No responses yet