Ankur Bawiskar
Tera Patron
Tera Patron

Some times we require to fetch/print the choice values/labels of a field to perform some validations or print them in an email notifications etc.

So here is a sample script which can be utilized and re-used as per the business requirement.

Note: This works in both global and scoped application

I just took an example of incident and change_request table and field as close_code

Script: For incident table

var choices = GlideChoiceList.getChoiceList("incident", "close_code");

for (var i = 0; i < choices.getSize(); i++){
		var choiceValue = choices.getChoice(i).getValue();
		var choiceLabel = choices.getChoice(i).getLabel();
		gs.info("Choice Label -> " + choiceLabel + " Choice Value ->" + choiceValue);
	
}

Choice Table:

find_real_file.png

Output:

find_real_file.png

Another Example for change_request table and field as close_code

Script: For change_request table

var choices = GlideChoiceList.getChoiceList("change_request", "close_code");

for (var i = 0; i < choices.getSize(); i++){
		var choiceValue = choices.getChoice(i).getValue();
		var choiceLabel = choices.getChoice(i).getLabel();
		gs.info("Choice Label -> " + choiceLabel + " Choice Value ->" + choiceValue);
	
}

Choice Table:

find_real_file.png

Output:

find_real_file.png

Thanks for reading the blog and do provide your inputs/suggestions if any.

Hope you find this article helpful. Don’t forget to Mark it Helpful, Bookmark.
Thanks,
Ankur Bawiskar

ServiceNow MVP 2021,2020,2019,2018

Developer MVP 2021

My Articles & Blogs

3 Comments