
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 10:21 AM
Can someone help me understand why the below is script is not returning any values?
Within the custom form users fill out there is a field called 'submission_type' that is required. Whenever the submission type is 'R.S.G.' I only want to return the 'R.S.G.' products.
Within the Product Table I have 10 values populated with 'R.S.G.', but its not returning any of those products.
var FilterProductList = Class.create();
FilterProductList.prototype = {
initialize: function() {
},
FilterProductList:function() {
var gp = ' ';
var a = current.submission_type;
//return everything if the submission_type value is empty
if(!a)
return;
//ConnectUs Products has the business unit to product relationship
var grp = new GlideRecord('x_hemas_connectus2_connectus_products');
grp.addQuery('business_unit',a);
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of products if there is more than one
gp += (',' + grp.product);
}
else {
gp = grp.product;
}
}
// return quired products
return 'sys_idIN' + gp;
},
type: 'FilterProductList'
};
Screen shot from custom form where no products are available to select
Screen Shot from Product Table
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 01:41 PM
Hi Edwin,
Can you make sure that 'Product' field on 'x_hemas_connectus2_connectus_products' table is a reference field?
If so, then may be put in some log entries to see if the info is correct.
Like-
gs.log('Submission type from Script Include: ' + current.submission_type); //before -> //return everything if the submission_type value is empty
gs.log('sysIDs returned: ' + gp); //before the last return statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 10:27 AM
Hi Edwin,
The Reference qualifier works on the server side. So if the user changes the submission type value, it cannot be processed by the reference qualifier. When the ref qualifier works, it only takes the initial value of the submission type field, which I assume is 'None' by default?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 10:29 AM
Try saving the record with the submission type = R.S.G and open the record and then check to see if any values are returned. If they do, you know the reason! If they are not even then, may be there's some other issue we can debug.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 11:09 AM
Thanks for your assistant, I tried saving the record with R.S.G. as the submission type but not values where return when checking the product field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 11:23 AM
Hi Edwin,
Please keep below line in your Reference qual
javascript: new FilterProductList().ProductFunction(current.variables.submission_type);
and update your code as below.
var FilterProductList = Class.create();
FilterProductList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ProductFunction: function(submission_type){
var gp = ' ';
var a = submission_type;
//return everything if the submission_type value is empty
if(!a)
return;
//ConnectUs Products has the business unit to product relationship
var grp = new GlideRecord('x_hemas_connectus2_connectus_products');
grp.addQuery('business_unit',a);
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of products if there is more than one
gp += (',' + grp.product);
}
else {
gp = grp.product;
}
}
// return quired products
return 'sys_idIN' + gp;
},
type: 'FilterProductList''
});
please go through the wiki for more information - http://wiki.servicenow.com/index.php?title=Adding_Dependent_Reference_Variables#gsc.tab=0
Regards,
Lavanya