How to manage choices in glide_list type field

SunilKumar_P
Giga Sage

Hi,

 

I have created a field of type 'glide_list' as users want to select multiple values in it and have added choices to this field. However, I am unable to add or remove options on this field based on other field value.

 

Any suggestions would be greatly appreciated.

 

Regards,

Sunil

1 ACCEPTED SOLUTION

Hey Sunil,

 

I did some testing on my own and I was able to get this to work (in contrast to my previous reply). This is a little experimental (and guesswork), so your millage may very. Try this in your onChange client script:

 

g_form.removeOption('choice.incident.<variable_name>', '<choice_value>');

 

Replace <variable_name> with the Column Name of your variable, and <choice_value> with your choice Value. If you are on a different table, try replacing incident with your table name (or inspect the HTML to see what is listed for that element).

 

Basically I inspected the HTML element for the Glide List field and saw that choice.incident was a prefix of the field name. Running g_form.RemoveOption() in my browser console successfully removed the option. See attached for examples.

 

Remember that you will need to use g_form.addOption() to re-add any options you removed client-side if needed.

Hope this helps! Let me know if you need an example of a client script.

View solution in original post

10 REPLIES 10

Zach N
Tera Guru

Hey Sunil!

 

EDIT: Please see my reply to Sunil for how to remove options from a Glide List. Other information in this post can be used for alternatives.

 

Unfortunately to my knowledge a List can't be manipulated in the same way a Choice List can be (options can't be added or removed from the selection, though they can be removed from the field once they are selected).

 

You could reference another table and use the Advanced Reference Qualifier to make choices dynamic. Using JavaScript you can use fields on the form. For example:

 

javascript&colon; "company=" + current.company

 

You could also use a Dependent Field to drive the choices.

 

If you can reference another table, you might also be able to dynamically change the reference qualifier using the GlideList API.

 

Another option might be creating different fields with different options and hiding / showing them depending on your needs. This is likely to get a little messy.

 

Beyond that, if you really need to limit the choices using the default Choice table, you could create a custom GlideAjax script include that dynamically marks options as active / inactive, but this is going to be resource intensive and slow.

 

Hope that helps!

Hi @Zach N, Thanks for your suggestions. I have tried to reference the sys_choice table as it contains the choice records but the table itself is not shown in the list. I could see 'Choice Set' table but it will not help in this scenario.

 

I am exploring the other possibilities, will update if I get any working solution.

Hey Sunil,

 

I did some testing on my own and I was able to get this to work (in contrast to my previous reply). This is a little experimental (and guesswork), so your millage may very. Try this in your onChange client script:

 

g_form.removeOption('choice.incident.<variable_name>', '<choice_value>');

 

Replace <variable_name> with the Column Name of your variable, and <choice_value> with your choice Value. If you are on a different table, try replacing incident with your table name (or inspect the HTML to see what is listed for that element).

 

Basically I inspected the HTML element for the Glide List field and saw that choice.incident was a prefix of the field name. Running g_form.RemoveOption() in my browser console successfully removed the option. See attached for examples.

 

Remember that you will need to use g_form.addOption() to re-add any options you removed client-side if needed.

Hope this helps! Let me know if you need an example of a client script.

@Zach N - Thanks for helping me here. Your suggestion did work. I really appreciate you taking time to help me on this.

Of course! Glad it worked!