Client Script to Filter Choices Works in Back Office but Not in CSM Workspace

ammar_k
Tera Contributor

Hi everyone,

I'm facing an issue with a client script that filters the choices of a field based on another field's selection. The script works perfectly in the back office (classic UI), but it doesn't apply the filtering in the CSM Workspace.

Here’s what I’ve tried:

  • Ensured the script runs on onChange of the dependent field.
  • The UI Type is set to ALL.

Has anyone encountered this issue before? Do I need to handle this differently in CSM Workspace?

Thanks in advance for any help!

This is a part of the code i am using

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === ''){
      return;
   }
   
g_form.clearOptions('u_claim_subtypes'); 
g_form.addOption('u_claim_subtypes', '--None--',"--None--");
   if (newValue == '30')
   
   {
 g_form.clearOptions('u_claim_subtypes'); 
g_form.addOption('u_claim_subtypes', 'Penalties_Admin',"3.1 Penalties - Admin");
g_form.addOption('u_claim_subtypes', 'Penalties_Back_orders',"3.2 Penalties - Back orders");
g_form.addOption('u_claim_subtypes', 'Penalties_Late_delivery','3.3 Penalties - Late delivery');
   }
   else if(newValue == '40') {
	g_form.clearOptions('u_claim_subtypes'); 
	g_form.addOption('u_claim_subtypes', 'IT_Issue',"4.1 IT Issue");
  }
}



5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@ammar_k 

are you sure the field on which onChange is running is present in workspace view?

the field to which option is added is present in that workspace view?

what came in alert?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    alert('inside onchange');

    g_form.clearOptions('u_claim_subtypes');
    g_form.addOption('u_claim_subtypes', '--None--', "--None--");
    if (newValue == '30')

    {
        alert('my value' + newValue);
        g_form.clearOptions('u_claim_subtypes');
        g_form.addOption('u_claim_subtypes', 'Penalties_Admin', "3.1 Penalties - Admin");
        g_form.addOption('u_claim_subtypes', 'Penalties_Back_orders', "3.2 Penalties - Back orders");
        g_form.addOption('u_claim_subtypes', 'Penalties_Late_delivery', '3.3 Penalties - Late delivery');
    } else if (newValue == '40') {
        g_form.clearOptions('u_claim_subtypes');
        g_form.addOption('u_claim_subtypes', 'IT_Issue', "4.1 IT Issue");
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@ammar_k 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello,

Thank for the explanation I made the field visible and this solved the issue.
but now I have another problem, 
after saving the record, if i try to change the value of the field A, then all choices would be available in the field B and they won't be filtered.

@ammar_k 

Glad to know that my comment to ensure the field is present on that view worked for you.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader