- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 07:27 AM
Hello NowCommunity,
On the above form,
Field1 (Reference to cmdb_ci_pc_hardware table) : User can select their device here.
Field2 (String field) : value is populated once the above field is updated. (GlideAjax - value derived from cmdb_ci_pc_hardware record )
Field3 (Reference) : Here I want to return catalog items whose name starts with 'ex'.
To do so,
i have to do it via on-change client script & script include only (due to my particular requirement). i have a success but the reference field is not getting updated.
SCRIPT INCLUDE :
var getSoftwareByCategory = Class.create();
getSoftwareByCategory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateenv:function() {
var env = this.getParameter('sysparm_env_ns');
var RerurnItem = [];
if (env == 'Normal Secure') {
var gr1 = new GlideRecord('pc_product_cat_item');
gr1.addEncodedQuery('nameSTARTSWITHxe');
gr1.query();
while (gr1.next()) {
RerurnItem.push(gr1.getUniqueValue());
}
}
return 'sys_idIN' + RerurnItem;
},
type: 'getSoftwareByCategory'
});
CLEINT SCRIPT :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var env = g_form.getValue('environment'); // field 2 value
var ga = new GlideAjax('getSoftwareByCategory');
ga.addParam('sysparm_name','populateenv');
ga.addParam('sysparm_env_ns', env); // also tried new value
ga.getXML(getCat);
function getCat(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('returned value : '+answer);
}
}
REFRENCE FIELD UPDATED:
Result :
Iam able to get the sys_id on the client side, but the reference field is not getting updated....
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 08:01 AM
Hello Sohail,
I belive you need to include another function for reference qualifier or comment the this.getParameter() line. In below example _populateenv() function is created :
var getSoftwareByCategory = Class.create();
getSoftwareByCategory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateenv:function() {
var env = this.getParameter('sysparm_env_ns');
var RerurnItem = [];
if (env == 'Normal Secure') {
var gr1 = new GlideRecord('pc_product_cat_item');
gr1.addEncodedQuery('nameSTARTSWITHxe');
gr1.query();
while (gr1.next()) {
RerurnItem.push(gr1.getUniqueValue());
}
}
return 'sys_idIN' + RerurnItem;
},
_populateenv: function(env) {
var RerurnItem = [];
if (env == 'Normal Secure') {
var gr1 = new GlideRecord('pc_product_cat_item');
gr1.addEncodedQuery('nameSTARTSWITHxe');
gr1.query();
while (gr1.next()) {
RerurnItem.push(gr1.getUniqueValue());
}
}
return 'sys_idIN' + RerurnItem;
},
type: 'getSoftwareByCategory'
});
Now in you reference Qualifier put the below:
javascript:new global.getSoftwareByCategory()._populateenv(current.variables.<field2_name>);
Also in attributes on field3 put ref_qual_elements=<your_field2_name>
Please mark my respsone as helpful/correct, if it answer your question.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 07:54 AM
So you want to set the query for Field 3 ?
in your Client Script.
var filter = g_list.get(‘field_3');
filter.setQuery(‘active=true’)
https://servicenowthink.wordpress.com/2021/02/05/how-to-modify-reference-qualifiers-with-catalog-client-script-servicenow/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 08:00 AM
Hi
you missed () braces after script include name on reference qualifier.
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 08:01 AM
Hi Sohail,
In reference qualifier, you are missing brackets for script include and parameter in function.
JavaScript: new getSoftwareByCategory().populateenv(current.variables.variable_name);
Try this.
If it does not works, check that parameter env is getting passed in Script Include else try by getting that parameter in initialize() function of Script include. Please mark this solution as correct answer and helpful if you are able to solve your issue.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2022 08:01 AM
Hello Sohail,
I belive you need to include another function for reference qualifier or comment the this.getParameter() line. In below example _populateenv() function is created :
var getSoftwareByCategory = Class.create();
getSoftwareByCategory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateenv:function() {
var env = this.getParameter('sysparm_env_ns');
var RerurnItem = [];
if (env == 'Normal Secure') {
var gr1 = new GlideRecord('pc_product_cat_item');
gr1.addEncodedQuery('nameSTARTSWITHxe');
gr1.query();
while (gr1.next()) {
RerurnItem.push(gr1.getUniqueValue());
}
}
return 'sys_idIN' + RerurnItem;
},
_populateenv: function(env) {
var RerurnItem = [];
if (env == 'Normal Secure') {
var gr1 = new GlideRecord('pc_product_cat_item');
gr1.addEncodedQuery('nameSTARTSWITHxe');
gr1.query();
while (gr1.next()) {
RerurnItem.push(gr1.getUniqueValue());
}
}
return 'sys_idIN' + RerurnItem;
},
type: 'getSoftwareByCategory'
});
Now in you reference Qualifier put the below:
javascript:new global.getSoftwareByCategory()._populateenv(current.variables.<field2_name>);
Also in attributes on field3 put ref_qual_elements=<your_field2_name>
Please mark my respsone as helpful/correct, if it answer your question.
Thanks