Use label or name instead of value in sysparm_query for PickList value filtering

csikid
Giga Contributor

Hi,


Similar to Solved: pass display value instead of sys_id in sysparm_qu... - ServiceNow Community

However it doesn't seem to work for "PickList" properties. Tried with .name and .label but no luck.

Is there any way to filter for name instead of value for PickLists?

 

The UI filter element seems to get the values from a xmlhttp.do POST call with sysparm_processor: PickList.

 

Currently we are still on Paris verison.

1 REPLY 1

Punit S
Giga Guru

n ServiceNow, for choice and reference fields, the getDisplayValue() method returns the display value for that field, while the getValue() method returns the actual value, which is the sys_id of the record.

In the case of picklist fields, you can use the getDisplayValue() method to get the display value of the selected option, and then use that value in your filtering. Here is an example of how you can filter a list using a picklist field:

 

var gr = new GlideRecord('incident');
gr.addQuery('category', 'Network');
gr.addQuery('subcategory', 'Wireless'); // This is a picklist field
gr.addQuery('subcategory', gr.getEncodedQuery()); // Add encoded query for filtering on picklist display value
gr.query();

while (gr.next()) {
  // Do something with filtered incidents
}

In the example above, the subcategory field is a picklist field. We add a query for the actual value of the field ('Wireless' in this case), and then add a second query for the encoded query for filtering on the display value of the field ('subcategory=Wireless' in this case).

Using this approach, you should be able to filter picklist fields based on the display value.

 

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit