- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 09:17 PM
I have a requirement to pass value from onChange client script for list type field to script include. Am using the below code but getting undefined value.
Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 12:01 AM
Reference qualifier wont work using "g_form.setReferenceQualifier" . Instead of using onChange client script you will need to use Advanced Reference Qualifier for the field where you want the reference qualifier to be applied. You can change the function "getChoices" to accept the parameter as follows:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 09:34 PM - edited 05-14-2025 09:35 PM
Hi @Aaviii ,
You're querying the sys_choice table by sys_id, but sys_choice usually doesn't use sys_id directly as a reference from form selections. You may actually be wanting to get choices for a specific field, where the element, name, and value columns are more relevant.
If you're trying to pass the selected value from a choice list field and want to retrieve other dependent choices based on that value, you might do better using the value field, not sys_id.
✅Corrected Script Include:
var Test = Class.create();
Test.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getChoices: function() {
var firstFieldValue = this.getParameter('sysparm_first_value');
var result = [];
// Assuming you're trying to use the 'value' field, not sys_id
var gm = new GlideRecord('sys_choice');
gm.addQuery('dependent_value', firstFieldValue);
gm.query();
while (gm.next()) {
result.push(gm.getValue('sys_id'));
}
return JSON.stringify(result);
},
type: 'Test'
});
Client Script (No Change Needed for Ajax Call):
Just make sure your newValue is the actual value of the selected choice, which is typically true for choice fields.
If the solution is correct, please give Helpful
thanks
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 09:37 PM
what's your requirement here?
are you trying to apply reference qualifier via g_form object?
share some details and screenshots.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 10:18 PM
Yes, I have 2 fields of list type. Based on selection in first field, I want dependent value in second field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 10:04 PM
Hi @Aaviii ,
As the type of field is list then you must be getting comma-separated list of sys_ids rather then just a single sys_id so you can use the following script:
Client Script:
Please mark the answer helpful and correct if it resolves the issue. Happy scripting
-Shantanu