How to add choice list dynamic in future if required

PraveenS8474123
Tera Contributor

example requirement
How to Create a Dynamic Language List Without Using a Separate Table?

I need to create a dynamic dropdown list for languages (e.g., German, English) in a form. The key constraints are:

  • I should be able to add more languages later (e.g., Hindi, Chinese, etc.).
  • I cannot create a separate table to store the language list.
  • I want to avoid using scripts (like Script Includes or Client Scripts) so that it's easy for other developers to maintain in the future.


 

4 REPLIES 4

GlideFather
Tera Patron

Hi @PraveenS8474123,

 

have you installed and activated the language packages?

It's a form of internationalisation plugins

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hi @GlideFather 
I have given language as example requirement. Main aim to add Dynamic List Without Using a Separate Table

@PraveenS8474123 and dynamic list to what field?

If it is a choice type then you can use [sys_choice] table and then dynamically hide/display the options with client script.

 

It'd be on change or on load according to your exact requirement, get inspired from this post:

https://www.servicenow.com/community/developer-forum/removeoption-and-addoption/m-p/1919129/highligh...

 

Let me know if this answered your question

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@PraveenS8474123 or here:

 

GlideForm (g_form) - Client

 

GlideForm - addOption(String fieldName, String choiceValue, String choiceLabel)

Adds a choice to the end of a specified choice list field.

ParametersName Type Description
fieldNameStringName of the field in which to add the choice field option.
choiceValueStringValue to store in the database.
choiceLabelStringValue to display.
ReturnsType Description
void 

Example

Explain this code
g_form.addOption('priority', '6', '6 - Really Low');
 

GlideForm - addOption(String fieldName, String choiceValue, String choiceLabel, Number choiceIndex)

Adds a choice to the list field at the position specified.

Note: Duplicate list labels are not supported in Service Portal. For example, items with label text matching another label are ignored and not added to the list.
 
ParametersName Type Description
fieldNameStringName of the field in which to add the choice field option.
choiceValueStringValue to store in the database.
choiceLabelStringValue to display.
choiceIndexNumberOrder of the choice in the list. The index is a zero-based array.
ReturnsType Description
void 

Example

Explain this code
g_form.addOption('priority', '2.5', '2.5 - Moderately High', 3);

 

 

GlideForm - removeOption(String fieldName, String choiceValue)

Removes the specified option from the specified choice list.

ParametersName Type Description
fieldNameStringName of the field from which to remove the option from the choice list.
choiceValueStringValue stored in the database. This is not the label.
ReturnsType Description
void 

Example

Explain this code
g_form.removeOption('priority', '1');
 
 
I believe this answered your question, please feel free to accept this for solution or tell me what would it take for it... thanks!
———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */