- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2023 11:34 PM
I created an onchange Client Script on Configuration item field of incident table. Used GlideAjax and Script-Include.
The script include returns the company, manufacturer and the asset_tag value of the configuration item being selected.
But somehow it's returning undefined.
I tried using array, object and string as well to return the value from the script include but still the same result.
I even tried to match the sys_id instead of the name field.
I'm attatching the screenshots of Client script, script include and the output here.
Looking forward for the solution.
Thankyou.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 09:24 AM - edited ‎11-04-2023 09:26 AM
@moni170 Here is the source of your issue.
Please try updating your code as follows and see if it works for you.
cmdb: function() {
var obj = ‘’;
var ab = this.getParameter(‘sysparm_ci’);
var gr = new GlideRecord(‘cmdb_ci’);
gr.addQuery(‘sys_id’, ab);
gr.query();
if (gr.next()) {
obj = obj + gr.manufacturer.toString() + ',' + gr.company.toString() + ',' + gr.asset_tag.toString();
}
return obj;
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 11:19 AM
Hey @moni170 ,
you are missing .next() in script include. Please correct it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 12:08 AM
Hi,
You should change the script include function "cmdb" like gr.addQuery('sys_id',ab)
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 12:10 AM
Hi @moni170
In script include, write below code like below
cmdb : function (){
/* 1. Declare array*/
var result =[];
/*2. Glide record on your table */
var gr = new GlideRecord('table_name');
gr.addQuery('field_name','your_query');
gr.query();
while (gr.next()){
var obj ={};
obj.company = gr.getValue('company');
obj.asset = gr.getValue('asset_tag');
//You can add more as per your need
/*3. Push object in result array*/
result.push(JSON.stringify(obj));
}
/*Return the result*/
return result.toString();
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 09:24 AM - edited ‎11-04-2023 09:26 AM
@moni170 Here is the source of your issue.
Please try updating your code as follows and see if it works for you.
cmdb: function() {
var obj = ‘’;
var ab = this.getParameter(‘sysparm_ci’);
var gr = new GlideRecord(‘cmdb_ci’);
gr.addQuery(‘sys_id’, ab);
gr.query();
if (gr.next()) {
obj = obj + gr.manufacturer.toString() + ',' + gr.company.toString() + ',' + gr.asset_tag.toString();
}
return obj;
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2023 11:12 AM