- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hellow,
I'm currently trying to learn how to properly call a Script Include from a List Collector variable's Reference Qualifier.
However, it seems that the list still returns data regardless of whether the Reference Qualifier is calling the Script Include or not.
Could someone please review my code and let me know where I might have gone wrong? Thank you!
List Collector Variable:
Script Include: - It should only return a few inactive records if it is working correctly.
var SoftwareName = Class.create();
SoftwareName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSoftwareNameRefQual: function() {
var gr = new GlideRecord('u_software_inventory');
gr.addQuery('active', false); // Only inactive records
gr.query();
var softwareNames = [];
while (gr.next()) {
var name = gr.getValue('u_software_name');
if (name)
softwareNames.push(name);
}
return softwareNames.join(',');
},
type: 'SoftwareName'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why you require script include?
what do you mean by few records? how many 5 or 10 or 100?
you can directly form the encoded query and copy paste there
javascript: 'u_active=false';
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
3 weeks ago - last edited 3 weeks ago
Hi @Erica2 ,
Based on your requirement you don't need a script include for this unless you want to validate something or fetching records from another table than glide list table.
Just add the condition to the reference qualifier field:
javascript:'active=false'; // OR just active=false
Thanks
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello @Erica2, you seem to have couple of problems in your code, could you plz try as below:
- change your ReferenceQualifier as below
javascript: new global.softwareName().getSoftwareNameRefQual();
- change your return statement as
return "nameIN" + softwareNames.join(',');
P.S: Since you are looking up by name, and there may be more than one entry with the same name, you might find duplicates in your list. It's better to return the sys_id to be on the safer side.
Regards,
Nishant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
adding the screenshot of reference qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Erica2 ,
Based on your requirement you don't need a script include for this unless you want to validate something or fetching records from another table than glide list table.
Just add the condition to the reference qualifier field:
javascript:'active=false'; // OR just active=false
Thanks
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Erica2 ,
List collector accepts sys_id's as return value not the names, so change the script as mentioned below:
ar SoftwareName = Class.create();
SoftwareName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSoftwareNameRefQual: function() {
var gr = new GlideRecord('u_software_inventory');
gr.addQuery('active', false); // Only inactive records
gr.query();
var softwareNames = [];
while (gr.next()) {
var name = gr.getValue('u_software_name');
if (name)
softwareNames.push(gr.getUniqueValue());
}
return softwareNames.join(',');
},
type: 'SoftwareName'
});
Mark this as helpful and correct if this solves your question.
Thanks,
Yaswanth.