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

Rahul Talreja
Mega Sage
Mega Sage

Hi @keval3 ,
Do you mean "Reverse if false" script?

Can you please share what is desired output and what are you getting now?

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

Hi Rahul,

My script is not working at the Reverse point Like when I choose Category and subcategory as per my requirement the variable is populating fine, but after that when I choose deferent category and sub category still those variable are visible at that time variable should be hide.

 

Thanks & Regards

KP

keval3
Tera Contributor

Hi Rahul,

My script is not working at the Reverse point Like when I choose Category and subcategory as per my requirement the variable is populating fine, but after that when I choose deferent category and sub category still those variable are visible at that time variable should be hide. I have right reverse condition as well but it's not working.

 g_form.setDisplay('business_unit',false);
g_form.setMandatory('business_unit', false);

 

Thanks & Regards

KP

Try to set mandatory to false first and then hide the field, because you can not hide a mandatory field, this should fix your problem.

 

g_form.setMandatory('business_unit', false);

g_form.setDisplay('business_unit',false);


But it is going to be easier to maintain if you switch to UI Policy.

Cheers, and have a great day!
Stefan