I'm getting: org.mozilla.javascript.NativeArray@f28434 when i tried to fecth the data in client
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 04:49 AM
i'm taking some data from the include script: an array, but when i call it it tells me from this error in the alert 'org.mozilla.javascript.NativeArray@f28434' how can i fix it?
my Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('get_capibility_level_1');
ga.addParam("sysparm_name", "getCapability");
ga.getXML(getValue);
function getValue(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
for (var i = 0; i < answer.length; i++) {
if (answer[i] == g_form.getValue("u_atrust_taxonomy_1")) {
alert('test');
}
}
}
}
my script include:
var get_capibility_level_1 = Class.create();
get_capibility_level_1.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCapability: function(){
var gr = new GlideRecord('cmdb_ci_business_capability');
gr.addEncodedQuery('hierarchy_level=1');
gr.query();
var arr = [];
while(gr.next()){
gs.info(gr.sys_id);
arr.push(gr.sys_id);
}
return arr;
},
type: 'get_capibility_level_1'
});
i tried to do: return JSON.stringify(arr) but it's the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 04:56 AM
try this
script include
var get_capibility_level_1 = Class.create();
get_capibility_level_1.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCapability: function(){
var gr = new GlideRecord('cmdb_ci_business_capability');
gr.addEncodedQuery('hierarchy_level=1');
gr.query();
var arr = [];
while(gr.next()){
arr.push(gr.getUniqueValue());
}
return arr.toString();
},
type: 'get_capibility_level_1'
});
client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('get_capibility_level_1');
ga.addParam("sysparm_name", "getCapability");
ga.getXML(getValue);
function getValue(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer.indexOf(g_form.getValue("u_atrust_taxonomy_1")) > -1)
alert('test');
}
}
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
11-22-2022 05:01 AM
Use below scripts.
Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('get_capibility_level_1');
ga.addParam("sysparm_name", "getCapability");
ga.getXML(getValue);
function getValue(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
alert(answer);
for (var i = 0; i < answer.length; i++) {
if (answer[i] == g_form.getValue("u_atrust_taxonomy_1")) {
alert('test');
}
}
}
}
Script Include
var get_capibility_level_1 = Class.create();
get_capibility_level_1.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCapability: function(){
var gr = new GlideRecord('cmdb_ci_business_capability');
gr.addEncodedQuery('hierarchy_level=1');
gr.query();
var arr = [];
while(gr.next()){
gs.info(gr.getValue('sys_id'));
arr.push(gr.getValue('sys_id'));
}
return JSON.stringify(arr);
},
type: 'get_capibility_level_1'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 05:51 AM
Hi @Fabrizio Joaqui,
First try to log what you are getting in the array in your script include. Add below line before return statement and after while loop.
gs.info('Array data: '+arr.toString(),'Your name'); // if you will add your name, then you can filter the logs with source as your name and it will be easy to see the result.
This will help you understand if you are setting correct data in array or not and based on that we can see what can be done.
Mohit Kaushik
ServiceNow MVP (2023-2025)