On Change Catalog Client script issue on dependency fields

Rajkumar Bokken
Tera Contributor

Hi All,

 

I have a catalog item.

Added variable select box (persona grouping) and gave few values in it.

added one more variable select box (persona) and added few values in it which are dependent on persona grouping.

wrote a onChange catalog client script.

 

Issue: when i open form and select sales Option in grouping, i get only sales related options in persona but when i change sales to IT then i get sales and IT related both options  in the same way if i change options in grouping i see other options as well but requirement is i should get only IT related options when i select IT and if i select any other option in grouping i need to get only that option related values in persona.

It seems like the issue is related to not clearing the existing options properly when the controlling variable changes.

 

RajkumarBokken_0-1705059629229.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

 

    var controllingVar = g_form.getValue('u_salesforce_persona_grouping');

    var dependentVar = g_form.getControl('u_salesforce_persona1');

 

    // Clear existing options

    dependentVar.options.length = 0;

 

    // Add options based on the value of the controlling variable

    if (controllingVar == 'Sales') {

        g_form.addOption('u_salesforce_persona1', 'Commercial Sales', 'Commercial Sales');

        g_form.addOption('u_salesforce_persona1', 'Field Sales', 'Field Sales');

        g_form.addOption('u_salesforce_persona1', 'GEST Leadership', 'GEST Leadership');

        g_form.addOption('u_salesforce_persona1', 'Partner Sales', 'Partner Sales');

        g_form.addOption('u_salesforce_persona1', 'Partner Sales Operations', 'Partner Sales Operations');

        g_form.addOption('u_salesforce_persona1', 'Presales', 'Presales');

        g_form.addOption('u_salesforce_persona1', 'Presales Manager', 'Presales Manager');

        g_form.addOption('u_salesforce_persona1', 'Sales Admins', 'Sales Admins');

        g_form.addOption('u_salesforce_persona1', 'Sales Leadership', 'Sales Leadership');

        g_form.addOption('u_salesforce_persona1', 'Sales Management', 'Sales Management');

        g_form.addOption('u_salesforce_persona1', 'Sales Operations', 'Sales Operations');

        g_form.addOption('u_salesforce_persona1', 'Wider Sales Operations', 'Wider Sales Operations');

    } else if (controllingVar == 'IT') {

        g_form.addOption('u_salesforce_persona1', 'Architect', 'Architect');

        g_form.addOption('u_salesforce_persona1', 'Architect Salesforce', 'Architect Salesforce');

        g_form.addOption('u_salesforce_persona1', 'Business Analyst', 'Business Analyst');

        g_form.addOption('u_salesforce_persona1', 'Developer Microsoft', 'Developer Microsoft');

        g_form.addOption('u_salesforce_persona1', 'Developer Salesforce', 'Developer Salesforce');

        g_form.addOption('u_salesforce_persona1', 'L1 Support', 'L1 Support');

        g_form.addOption('u_salesforce_persona1', 'Manager', 'Manager');

        g_form.addOption('u_salesforce_persona1', 'Project Manager', 'Project Manager');

        g_form.addOption('u_salesforce_persona1', 'Specialist Salesforce', 'Specialist Salesforce');

        g_form.addOption('u_salesforce_persona1', 'System Administrator', 'System Administrator');

    } else if (controllingVar == 'Service') {

        g_form.addOption('u_salesforce_persona1','Technical Sales', 'Technical Sales');

    } else if (controllingVar == 'Marketing') {

        g_form.addOption('u_salesforce_persona1', 'General Marketing', 'General Marketing');

        g_form.addOption('u_salesforce_persona1', 'Marketing', 'Marketing');

        g_form.addOption('u_salesforce_persona1', 'Marketing Operations', 'Marketing Operations');

        g_form.addOption('u_salesforce_persona1', 'LDR (similar to Sales)', 'LDR (similar to Sales)');

        g_form.addOption('u_salesforce_persona1', 'LDR Leadership (bulk reassign leads, lead assignment)', 'LDR Leadership (bulk reassign leads, lead assignment)');

    } else if (controllingVar == 'HR') {

        g_form.addOption('u_salesforce_persona1', 'Training', 'Training');

        g_form.addOption('u_salesforce_persona1', 'HR', 'HR');

    } else if (controllingVar == 'Partners') {

        g_form.addOption('u_salesforce_persona1', 'Deal Registration Partner', 'Deal Registration Partner');

        g_form.addOption('u_salesforce_persona1', 'License Partner Community', 'License Partner Community');

    } else if (controllingVar == 'Product Management') {

        g_form.addOption('u_salesforce_persona1', 'Product Management', 'Product Management');

    } else if (controllingVar == 'Analytics'){

        g_form.addOption('u_salesforce_persona1', 'Analytics', 'Analytics');

    } else if (controllingVar == 'Finance') {

        g_form.addOption('u_salesforce_persona1', 'Finance', 'Finance');

    } else if (controllingVar == 'Legal') {

        g_form.addOption('u_salesforce_persona1', 'Legal', 'Legal');

    } else if (controllingVar == 'Consultant'){

        g_form.addOption('u_salesforce_persona1', 'Consultant', 'Consultant');

    } else {

        // Default options if no condition is met

        g_form.addOption('-- None --', '-- None --');

   

    }

 

   

}

 

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Rajkumar Bokken,

 

Did you see my response below? You can clear the value's using the 'clearOptions' method used as follows: g_form.clearOptions('variablename'); 

Use this method in each 'if' / 'Else if' block of your script before you add the new options.

g_form.clearOptions('u_salesforce_persona1');

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

5 REPLIES 5

Robbie
Kilo Patron
Kilo Patron

Hi @Rajkumar Bokken,

 

g_form provides a method called 'clearOptions' used as follows: g_form.clearOptions('variablename'); 

Use this method in each 'if' / 'Else if' block of your script before you add the new options.

g_form.clearOptions('u_salesforce_persona1');

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Robbie
Kilo Patron
Kilo Patron

Hi @Rajkumar Bokken,

 

Did you see my response below? You can clear the value's using the 'clearOptions' method used as follows: g_form.clearOptions('variablename'); 

Use this method in each 'if' / 'Else if' block of your script before you add the new options.

g_form.clearOptions('u_salesforce_persona1');

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Robbie
Kilo Patron
Kilo Patron

Hi @Rajkumar Bokken,

 

Thanks for marking my response as Helpful. Did it resolve your issue? Are you now only seeing the values based on the controllingVar eg Sales? (And no longer seeing the older values from the previous controllingVar selections?

Can I help you close the question/query out? 

 

If my response answers your question, please mark this response correct by clicking on Accept as Solution

 

Thanks,

Robbie

Rajkumar Bokken
Tera Contributor

Hi @Robbie ,

 

Thanks for the help its working 🙂

 

Thanks,

Rajkumar Bokkena