- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 09:53 AM - edited 12-12-2024 10:59 AM
Hi, I have a list collector and a checkbox that I use together so that if the user selects the Check Box, it automatically selects all the values in the list collector.
The issue is that the list collector has a reference qualifier, and my Script Include doesn't appear to be handling it properly because the list of users is only really 10 or so but as you can see, all of them are returning.
Here is the reference qualifier: javascript: 'u_location='+current.variables.location;
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(", "));
}
});
}
Script Include:
var MyCatalogUtils = Class.create();
MyCatalogUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getRecords: function() {
var fieldName = this.getParameter('sysparm_field_name');
var catItem = this.getParameter('sysparm_cat_item');
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'
});
Any idea why the reference qualifier isn't being applied correctly?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 02:44 PM
I'm warming up to this approach. Since you know what the EncodedQuery should be and it's not going to change you can hard-code it with the location script variable instead of trying to manipulate the returned value. In either case you need to add a line to the Catalog Client Script like:
ga.addParam('sysparm_location' , g_form.getValue('v_location'));
Where 'v_location' is the name of the location variable, then add to the Script Include:
var location = this.getParameter('sysparm_location');
Then either use:
var encodedQuery = 'u_location='+location;
or try to manipulate the string value of your encodedQuery returned by the variableGR to match this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:24 AM
This is an ...interesting... way to go about this. You could try adding alerts and gs.info lines to see where it's going wrong. A more traditional approach is to pass the location variable value to the Script Include, which then just executes a GlideRecord on the list table, incorporating the reference qualifier logic. Since you want to set the value of the list variable, just push each retrieved user sys_id to an array, then return the joined array to set the value of the list variable in the Client Script to this comma-separated list of sys_ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 01:59 PM - edited 12-13-2024 07:31 AM
Hi Brad, I added some gs.info and it looks like this line of code isn't working properly.
var encodedQuery = variableGR.getValue('reference_qual');
tableLookupGR.addEncodedQuery(encodedQuery);The variable "encodedQuery" does return "javascript: 'u_location='+current.variables.location;" because that's exactly how the variable's type specifications is configured, but when that value is passed into the next line for the addEncodedQuery, that's where I think the issue lies because that format isn't generally used for an addEncodedQuery.
It is trying perform this:
tableLookupGR.addEncodedQuery(javascript: 'u_location='+current.variables.location);
This is not the appropriate way to use an addEncodedQuery.
How would you suggest I pass the location variable appropriately so that it is used correctly in the addEncodedQuery?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 02:44 PM
I'm warming up to this approach. Since you know what the EncodedQuery should be and it's not going to change you can hard-code it with the location script variable instead of trying to manipulate the returned value. In either case you need to add a line to the Catalog Client Script like:
ga.addParam('sysparm_location' , g_form.getValue('v_location'));
Where 'v_location' is the name of the location variable, then add to the Script Include:
var location = this.getParameter('sysparm_location');
Then either use:
var encodedQuery = 'u_location='+location;
or try to manipulate the string value of your encodedQuery returned by the variableGR to match this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2024 07:52 AM - edited 12-13-2024 08:36 AM
Hi @Brad Bowman
I did exactly as you said, and it worked!
This is the code I added to the client script in bold
And this is the script include code