when i select Company as HP at that time, only the associated departments of HP should be visible.

Community Alums
Not applicable

Hi There,

 

I have one requirement on Termination Catalog Item, 

In that i have company and department variables, company is reference to core_company, and department is a select box type of Variable, 

And If i select Company as HP then its associate departments only visible to requestor to select on the form.

and if i select HP then its  associate departments are visible which is fine, but i have multiple companies and those multiple companies having multiple associated departments, 

in my case, in code i have taken first company as HP , so if i select HP then the proper departments are company, but i want to select 'Dell'  company, for that i have taken If Condition, and then added the associated departments, but when i select Dell at that time i'm not getting only the departments associated with Dell, im getting the Departments of Dell with that HP departments also.

 

Please find the code i have written.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
  if (newValue == 'HP')
    alert('newValue');
    {
        g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department''Compliance''Compliance');
        g_form.addOption('new_department','Vendors','Vendors');
        alert('testtttttttt');
       
    }
    alert('2test');
    if (newValue == 'Dell')
    alert('Dell Test');
    {
     g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department', ' BMA', 'BMA');
        g_form.addOption('new_department', 'Research & Prod Dev', 'Research & Prod Dev');
g_form.addOption('new_department', 'Portfolio', 'Portfolio');
alert('Dell End');
}
if (newValue == 'Lenovo')

{
        alert('Lenovo');
        g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department', 'Tax Services', 'Tax Services');
        g_form.addOption('new_department', 'Property', 'Property');
        }
}
   
 
if i select HP then Proper Departments are coming,
if i select Dell, then departments of Dell with that departments of HP  also coming,
if i select Lenovo, then departments of Lenovo, departments of Dell, departments of HP all coming.
 
can anyone please help me, in above code where i made mistake, how can i get the proper solution.
 
Thanks,
Priya
   
   

 

 

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
g_form.clearOptions('new_department'); //remove all options
  if (newValue == 'HP')
    alert('newValue');
    {
        g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department', 'Compliance', 'Compliance');
        g_form.addOption('new_department','Vendors','Vendors');
        alert('testtttttttt');
       
    }
    alert('2test');
    if (newValue == 'Dell')
    alert('Dell Test');
    {
     g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department', ' BMA', 'BMA');
        g_form.addOption('new_department', 'Research & Prod Dev', 'Research & Prod Dev');
g_form.addOption('new_department', 'Portfolio', 'Portfolio');
alert('Dell End');
}
if (newValue == 'Lenovo')

{
        alert('Lenovo');
        g_form.addOption('new_department', '--None--', '--None--');
        g_form.addOption('new_department', 'Tax Services', 'Tax Services');
        g_form.addOption('new_department', 'Property', 'Property');
        }
}

 

Please mark my answer helpful and correct if it manages to address your question.

Community Alums
Not applicable

hi @Sandeep Rajput ,

 

Thanks for your response, 

i changed my script with your script but which is also not properly working, could you please help me is there any changes needed.

 

Thanks,

Priya

@Community Alums Could you please test the script in incognito mode, sometimes the scripts are cached by the browser which causes issues,

Venkata Rama Kr
Tera Contributor

Please clear out the choice values initially for every change on department. Try adding below line of code

g_form.clearOptions('new_department');
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    g_form.clearOptions('new_department');
    if (newValue == 'HP')