- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2024 08:23 AM - edited ‎12-12-2024 09:06 AM
I have a record producer with a list collector variable, and I am trying to accomplish adding a check box so that if the user checks the box, the list collector variable will select all items in the list.
When I try to test the functionality, I get this JavaScript/GlideAjax error.
Script Include:
var MyCatalogUtils = Class.create();
MyCatalogUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getRecords: function() {
var fieldName = this.getParameter('user_list'); // i entered the unique variable name
var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP
var variableGR = new GlideRecord('item_option_new');
variableGR.addQuery('name', fieldName);
variableGR.addQuery('cat_item', catItem);
variableGR.setLimit(1);
variableGR.query();
if (variableGR.next()) {
var tableLookupGR = new GlideRecord(variableGR.getValue('list_table'));
var encodedQuery = variableGR.getValue('reference_qual');
tableLookupGR.addEncodedQuery(encodedQuery);
var returnValues = [];
tableLookupGR.query();
while (tableLookupGR.next()) {
returnValues.push({
"value": tableLookupGR.getUniqueValue(),
"displayValue": tableLookupGR.getDisplayValue()
});
}
return JSON.stringify(returnValues);
}
},
type: 'MyCatalogUtils'
});
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var listCollectorName = "user_list";
if(g_list != "undefined"){
var listCollector = g_list.get(listCollectorName);
if(!listCollector)return;
}
if(newValue == 'false'){
g_form.setValue(listCollectorName , '');
return;
}
var ga = new GlideAjax('MyCatalogUtils');
ga.addParam('sysparm_name' , 'getRecords');
ga.addParam('sysparm_field_name' , listCollectorName);
ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());
ga.getXMLAnswer(function(response){
if(response == null)return;
response = JSON.parse(response);
if(listCollector){
response.forEach(function(el){
listCollector.addItem(el.value , el.displayValue);
});
} else {
var values = response.map(function(val){ return val.value;});
var display = response.map(function(val){return val.displayValue;});
g_form.setValue(listCollectorName , values.join(",") , display.join(", "));
}
});
}
Here are some screen captures.
The idea from this derived from this post: How To - Select all records for a list collector - ServiceNow Community
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2024 09:11 AM
I just had a quick look but it seems to me be your parameter names in the client script and script include do not match, i.e.:
Client script:
ga.addParam('sysparm_field_name' , listCollectorName);
ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());
While the Script Include is looking for different parameters:
var fieldName = this.getParameter('user_list'); // i entered the unique variable name
var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2024 09:11 AM
I just had a quick look but it seems to me be your parameter names in the client script and script include do not match, i.e.:
Client script:
ga.addParam('sysparm_field_name' , listCollectorName);
ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());
While the Script Include is looking for different parameters:
var fieldName = this.getParameter('user_list'); // i entered the unique variable name
var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2024 09:14 AM - edited ‎12-12-2024 09:44 AM
Hi Laszlo, thank you for responding.
I tried to change the parameters on the Script Include to mirror the Client Script so now it shows
The error no longer appears. Thank you Laszlo!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2024 01:58 AM
Neil, you would not need the 'sysparm_' part in the script include btw, so
var fieldName = this.getParameter('field_name');
var catItem = this.getParameter('cat_item');
should do the trick.