How to Show/Hide Options using g_form in client script.

Prabhu20
Tera Contributor

Hi,

Actually I need to show/hide options on one field based on another field.
I can achieve this using g_form.clearOptions() , addOption() & removeOption(). But, its actually removing or adding  options.

Is there any other way available to show or hide options other than the above specified. ?

1 ACCEPTED SOLUTION

Hi Prabhu,

you should create entry into UI messages table for those drop down values and adding option should be possible using getMessage()

refer below links for help

translations for onChange catalog client script through getmessage() method not working

Coding Help for retrieving the value from sys_message table

How to use gs.getMessage() to get the string translated?

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Hi,

for all options you need to create entry into that messages table

Regards
Ankur

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

Hi Ankur,

Yes, I have created 3 records in Messages table, though its getting translated value only for option 1. I don't know why its not showing values for options 2 & 3.

With Regards,
Prabhu V

Hi Prabhu,

try to logout and login again

Regards
Ankur

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

Hi Ankur,

Thanks for your support.!

Its working fine now, actually I have modified the getMessage() to be outside of if statement and assigned it to temporary variables.


Regards,
Prabhu V

You are welcome.

Do remember to mark responses which helped you as helpful.

Happy learning.

Regards
Ankur

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