On change Catalog client script: Code is not working

Bindhu1
Tera Contributor

Hello All, 
I'm attempting to make a field visible and mandatory, but it doesn't seem to be working. 

 

The variables are becoming mandatory, but they're not getting hidden. Could you please help me troubleshoot this?"

 

Here is the code : on change of checkbox 'servers_hosting_the_solution_9'

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
 
    var serversHostingChecked = g_form.getValue('servers_hosting_the_solution_9');
 
    // Make fields visible and mandatory based on the checkbox status
    if (serversHostingChecked) {
        g_form.setMandatory('new_servers_hosting_the_solution_9', true);
        g_form.setMandatory('server_s_to_remove_from_a_solution', true);
        g_form.setVisible('new_servers_hosting_the_solution_9', true);
        g_form.setVisible('server_s_to_remove_from_a_solution', true);
    } else {
        g_form.setMandatory('new_servers_hosting_the_solution_9', false);
        g_form.setMandatory('server_s_to_remove_from_a_solution', false);
        g_form.setVisible('new_servers_hosting_the_solution_9', false);
        g_form.setVisible('server_s_to_remove_from_a_solution', false);
    }
 
    // If one field is filled, make the other non-mandatory
    var var1Value = g_form.getValue('new_servers_hosting_the_solution_9');
    var var2Value = g_form.getValue('server_s_to_remove_from_a_solution');
 
    if (var1Value) {
        g_form.setMandatory('server_s_to_remove_from_a_solution', false);
    }
 
    if (var2Value) {
        g_form.setMandatory('new_servers_hosting_the_solution_9', false);
    }
}

 

1 ACCEPTED SOLUTION

Ritesh Kag
Kilo Guru

Hi @Bindhu1  would try using the Catalog UI Policies instead

write three UI Policies with below conditions and configure ui policy action appropriately -

 

1)UI POLICY  CONDITION { servers_hosting_the_solution_9 is true  & reverse if false checked}

               TWO UI POLICY ACTION -

                      { new_servers_hosting_the_solution_9 - visible true - mandatory true}

                       { server_s_to_remove_from_a_solution - visible true - mandatory true}

 

2)UI POLICY  CONDITION { new_servers_hosting_the_solution_9 is not empty  & reverse if false checked}

               1 UI POLICY ACTION -

                       { server_s_to_remove_from_a_solution  - mandatory false}

 

2)UI POLICY  CONDITION { server_s_to_remove_from_a_solution is not empty  & reverse if false checked}

               1 UI POLICY ACTION -

                       { new_servers_hosting_the_solution_9  - mandatory false}

This should work as you are expecting.

View solution in original post

3 REPLIES 3

Ritesh Kag
Kilo Guru

Hi @Bindhu1  would try using the Catalog UI Policies instead

write three UI Policies with below conditions and configure ui policy action appropriately -

 

1)UI POLICY  CONDITION { servers_hosting_the_solution_9 is true  & reverse if false checked}

               TWO UI POLICY ACTION -

                      { new_servers_hosting_the_solution_9 - visible true - mandatory true}

                       { server_s_to_remove_from_a_solution - visible true - mandatory true}

 

2)UI POLICY  CONDITION { new_servers_hosting_the_solution_9 is not empty  & reverse if false checked}

               1 UI POLICY ACTION -

                       { server_s_to_remove_from_a_solution  - mandatory false}

 

2)UI POLICY  CONDITION { server_s_to_remove_from_a_solution is not empty  & reverse if false checked}

               1 UI POLICY ACTION -

                       { new_servers_hosting_the_solution_9  - mandatory false}

This should work as you are expecting.

Hi @Ritesh Kag ,
Thank you for the detailed explanation. Everything is working perfectly. One thing to keep in mind is that the order of the last two UI policies should be lower than the first UI policy, or else this will cause an issue.

Astik Thombare
Tera Sage

.