Service Catalog - Client Script To Add Options To A Drop Down Field

billv6
Kilo Expert

Hello,

 

This is my first post here and I would like a help with a Client Script in the Service Catalog.

 

I have a Catalog Item named FILENET, inside the FILENET variable set, I have two variables (filenet_lob_1 and filenet_Role_1), these two variables should contain some of the Maintain Item Choices and the second variable (filenet_Role_1) MUST be dependent of what was chosen in the first variable (filenet_lob_1).

 

So, I've made the script below and it is not working, not sure if I'm doing it wrong or the problem above can not be solved using Client Script:

 

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

   

    if(newValue == oldValue){

          return;

    }

   

    //build a new list of dependent options

    var gp = new GlideRecord('sys_choice');

    gp.addQuery('Commercial', newValue);

    gp.addQuery('Field Underwriter/ Service Operations', 'filenet_Role_1');

    gp.addQuery('Field Underwriter/ Service Operations w/ Restricted Access', 'filenet_Role_1');

    gp.query();

    while(gp.next()){

          if (gp == "Commercial") {

                g_form.addOption('filenet_Role_1', gp.value, gp.label);

                g_form.addOption('filenet_Role_1', gp.value, gp.label);

          }

          else {

                g_form.clearOptions('filenet_Role_1');

          }

    }

}

 

I appreciate any ideas or some help! 🙂

 

Thanks!

7 REPLIES 7

billv6
Kilo Expert

Thanks a lot for the tips randrews!



I've got it working using the else if statement instead of if only. 🙂


Hi Bill



Can u show the code when I tried using the same logic when I select the particular value it gives be blank values on another drop down.


mamta... assuming i understand your issue correctly.. they can pick it on the form but after they submit the form .. the values don't appear correctly.. this is because you didn't list the values in the variable definition.. remember while you can set the display and value for the variable.. that only applies while the client script is loaded... once it SETS the value.. and the server tries to access that value.. if it isn't defined in the options you won't see it in reports etc...




so you HAVE to load all possible selections into the variable definition... then use the client script to control which ones show.