Reverse script is not working

keval3
Tera Contributor

Hi All,

I have create one script in catalog client script basis on category and subcategory some variable should display on service portal.it is working fine but revers script is not working please let me know the solution.  I have right down my script below.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var field1Value = g_form.getValue('u_hr_subcategory');
var field2Value = g_form.getValue('u_hr_category');
    alert(field1Value);
    // Add conditions based on your requirements
    if (field1Value == 'Position ID Creation' && field2Value == 'employee_data_management') {
        alert("fgg");
        g_form.setDisplay('business_unit', true);
        g_form.setMandatory('business_unit', true);
        g_form.setDisplay('sub_business_unit', true);
        g_form.setMandatory('sub_business_unit', true);
        g_form.setDisplay('region', true);
        g_form.setDisplay('sub_region', true);
        g_form.setDisplay('country', true);
        g_form.setDisplay('location', true);
        g_form.setDisplay('sub_location', true);
        g_form.setDisplay('function1', true);
        g_form.setDisplay('sub_function', true);
        g_form.setDisplay('department', true);
        g_form.setDisplay('designation', true);
        g_form.setDisplay('global_job_level', true);
        g_form.setDisplay('fixed_term_permanent_part_time_contractor', true);
        g_form.setDisplay('reporting_manager_ugdn_no', true);
        g_form.setDisplay('cost_center_if_available', true);
        g_form.setDisplay('manager_id', true);
        g_form.setDisplay('manager_name', true);
        g_form.setDisplay('recuriter_hrbp', true);
        g_form.setDisplay('replacement_of_name', true);
        g_form.setMandatory('region', true);
        g_form.setMandatory('sub_region', true);
        g_form.setMandatory('country', true);
        g_form.setMandatory('location', true);
        g_form.setMandatory('sub_location', true);
        g_form.setMandatory('function1', true);
        g_form.setMandatory('sub_function', true);
        g_form.setMandatory('department', true);
        g_form.setMandatory('designation', true);
        g_form.setMandatory('global_job_level', true);
        g_form.setMandatory('fixed_term_permanent_part_time_contractor', true);
        g_form.setMandatory('reporting_manager_ugdn_no', true);
        g_form.setMandatory('cost_center_if_available', true);
        g_form.setMandatory('manager_id', true);
        g_form.setMandatory('manager_name', true);
        g_form.setMandatory('recuriter_hrbp', true);
        g_form.setMandatory('replacement_of_name', true);
    } else {
alert("value chnaged");
      g_form.setDisplay('business_unit',false);
g_form.setMandatory('business_unit', false);
        alert("n");
 
        // Set mandatory properties to false for the fields that were made mandatory in the if block
        g_form.setMandatory('region', false);
        g_form.setMandatory('sub_region', false);
 
}

Thanks & Regards

KP

 

 

6 REPLIES 6

@keval3 ,
Try Setting up setMandatory to false before making them visible false.

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Stefan Georgiev
Tera Guru

Hello,
From the script that you have provided, you are looking for a UI Policy. You can create an UI Policy with the conditions that you are checking in the if condition <field1Value == 'Position ID Creation' && field2Value == 'employee_data_management'> and if those conditions are met you can create UI Policy Actions for the fields that you are setting to visible and mandatory, those here:

g_form.setDisplay('business_unit', true);
        g_form.setMandatory('business_unit', true);
        g_form.setDisplay('sub_business_unit', true);
        g_form.setMandatory('sub_business_unit', true);
        g_form.setDisplay('region', true);
        g_form.setDisplay('sub_region', true);
        g_form.setDisplay('country', true);
        g_form.setDisplay('location', true);
        g_form.setDisplay('sub_location', true);
        g_form.setDisplay('function1', true);
        g_form.setDisplay('sub_function', true);
        g_form.setDisplay('department', true);
        g_form.setDisplay('designation', true);
        g_form.setDisplay('global_job_level', true);
        g_form.setDisplay('fixed_term_permanent_part_time_contractor', true);
        g_form.setDisplay('reporting_manager_ugdn_no', true);
        g_form.setDisplay('cost_center_if_available', true);
        g_form.setDisplay('manager_id', true);
        g_form.setDisplay('manager_name', true);
        g_form.setDisplay('recuriter_hrbp', true);
        g_form.setDisplay('replacement_of_name', true);
        g_form.setMandatory('region', true);
        g_form.setMandatory('sub_region', true);
        g_form.setMandatory('country', true);
        g_form.setMandatory('location', true);
        g_form.setMandatory('sub_location', true);
        g_form.setMandatory('function1', true);
        g_form.setMandatory('sub_function', true);
        g_form.setMandatory('department', true);
        g_form.setMandatory('designation', true);
        g_form.setMandatory('global_job_level', true);
        g_form.setMandatory('fixed_term_permanent_part_time_contractor', true);
        g_form.setMandatory('reporting_manager_ugdn_no', true);
        g_form.setMandatory('cost_center_if_available', true);
        g_form.setMandatory('manager_id', true);
        g_form.setMandatory('manager_name', true);
        g_form.setMandatory('recuriter_hrbp', true);
        g_form.setMandatory('replacement_of_name', true);

And you can just click the reverse if false checkbox on the UI Policy and it is going to revert them if the conditions are not met.

Hope that this is going to help you!