How to get value of multiple choice types value gs.getpriority() method.

sibasundarsahoo
Tera Contributor

Does anyone have any idea of how to fetch different choices in a property of type 'choice_list'? For example : the property 'change.conflict.modet' has two key value choices (Basic=basic, Advanced=advanced) and the default value is advance. So, if I run the statement on background script : gs.getProperty("change.conflict.modet"), I get the value 'advanced'. Now. if I want to fetch the other choice values (basics) using gs.getProperty() method, what should be the signature for that method ?

1 REPLY 1

Iraj Shaikh
Mega Sage
Mega Sage

Hi @sibasundarsahoo 

 

In ServiceNow, the `gs.getProperty()` method is used to retrieve the value of a system property. If you want to get the default value or the current value of a property, you would use `gs.getProperty("property_name")`. However, this method does not provide a way to fetch all the possible choices for a property of type 'choice_list'.

To fetch the different choices for a 'choice_list' property, you would typically need to access the `sys_choice` table where the choices for fields are stored. However, system properties that use choice lists do not store their choices in the `sys_choice` table like form fields do. Instead, they are often hardcoded into the system property definition.

If you want to programmatically access the choices for a system property, you would need to refer to the documentation or the system property definition where the choices are defined. Unfortunately, there is no standard API method like `gs.getProperty()` to retrieve all possible choices for a system property.

If you need to access the choices for a form field that uses a choice list, you can query the `sys_choice` table. Here's an example of how you might do that for a field on a form:

 

var choiceGR = new GlideRecord('sys_choice');
choiceGR.addQuery('name', 'table_name'); // Replace 'table_name' with the name of the table
choiceGR.addQuery('element', 'field_name'); // Replace 'field_name' with the name of the field
choiceGR.query();
while (choiceGR.next()) {
    gs.print(choiceGR.getValue('label') + '=' + choiceGR.getValue('value'));
}

 

 

For system properties, you would typically need to refer to the documentation or the instance where the property is defined to understand the available choices. If you need to present these choices within a script or application, you would likely have to hardcode them or store them in a custom table or script include that you can query.

Please mark this response as correct or helpful if it assisted you with your question.