Help showing choices in List Controller (Record Producer) for multi-selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 11:52 AM - edited ‎03-20-2025 01:15 PM
I have a variable on a Record Producer that needs to be multi-select. To accomplish this, I am using a list collector where the List table is Question Choice (question_choice) and the reference qualifier points to the script include:
javascript:GetChoicesForReqTests.getChoices().
My script include is written to pull in ONLY the choices for the question so that when the user is on the form, the filter is already populated with Question --> is --> What tests are on the exam (the question name). When I test out my form, all of the choices on the choice table appear. When I test my script in a background script it just says, "undefined". Can someone please tell me what's wrong with my script include?
var GetChoicesForReqTests = Class.create();
GetChoicesForReqTests.prototype = {
initialize: function() {},
getChoices: function() {
var choices = [];
//Find the qustion record based on the question_text field
var quesRec = new GlideRecord('item_option_new');
quesRec.addQuery('question_text', "What tests are on the exam?");
quesRec.query();
if (quesRec.next()) { //If my question is found
var getChoices = new GlideRecord('question_choice');
getChoices.addQuery('question', 'quesRec.sys_id');
getChoices.query();
while (getChoices.next()) {
choices.push(getChoices.toString()); //populate the list collector
}
}
return choices;
},
type: 'GetChoicesForReqTests'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 12:00 AM
Hello @SN_Levette
I assume there is only one List collector type variable and in that we have to show static choices. So, to achieve this requirement please follow the below steps:
1. Create choices in the Question Choice table
2. Fill the fields like Text, Value and in the Question field, add your Question that is "What tests are on the exam"
3. In the question choice table run a filter like:
- Question = What tests are on the exam
4. You will get all the question choices for this question
5. Copy the query
6. Paste that query in the Reference Qualifier in the "What tests are on the exam" variable using the below condition
- javascript: 'question=the_sys_id_of_question'
7. You will be able to see all the choices in the Variable
Please let me know if this works for you
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 12:45 AM
update as this and then invoke as this
var GetChoicesForReqTests = Class.create();
GetChoicesForReqTests.prototype = {
initialize: function() {},
getChoices: function() {
var choices = [];
//Find the qustion record based on the question_text field
var quesRec = new GlideRecord('item_option_new');
quesRec.addQuery('question_text', "What tests are on the exam?");
quesRec.query();
if (quesRec.next()) { //If my question is found
var getChoices = new GlideRecord('question_choice');
getChoices.addQuery('question', quesRec.sys_id);
getChoices.query();
while (getChoices.next()) {
choices.push(getChoices.toString()); //populate the list collector
}
}
return choices.toString();
},
type: 'GetChoicesForReqTests'
};
Also invoke like this
javascript: 'sys_idIN' + new GetChoicesForReqTests().getChoices();
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