- 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
06-23-2024 09:06 PM
Thank Stewe.
this article worked for me:
How to modify Reference Qualifiers with Catalog Client Scripts – ServiceNow – ServiceNow Think (word...
and this is the onChange client script: