Script Include returning null?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 12:11 AM
Hi all,
The following Script returning null value. I need consumer sys_id. Thanks in advance
Script Include -
var customerPhones = Class.create();
customerPhones.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
ConsumerS: function() {
var g = this.getParameter('syparm_cons');
var CONsumer = '';
gs.info("Include::::" + g);
var gr1 = new GlideRecord('sn_customerservice_product_service_support');
gr1.addQuery('sys_id', g);
gr1.query();
if (gr1.next()) {
CONsumer = gr1.consumer;
}
return CONsumer;
},
Client Script -
var ans = '';
var con = g_form.getValue('parent');
var ga1 = new GlideAjax('sn_customerservice.customerPhones');
ga1.addParam('syparm_name', 'ConsumerS');
ga1.addParam('syparm_cons', con);
ga1.getXML(HelloWorld);
function HelloWorld(response) {
ans = response.responseXML.documentElement.getAttribute("answer");
alert(ans);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 02:15 AM
Hi,
Share screenshots of both script include and client scripts
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 12:40 AM
hi
I found the issue in client script, refer corrected script below
Client Script -
ga1.addParam('sysparm_name', 'ConsumerS');
ga1.addParam('sysparm_cons', con);
also if possible use getXMLAnswer instead getXML, will get the answer alone not entire record
ga1.getXMLAnswer(HelloWorld);
function HelloWorld(response) {
var ans = response;
alert(ans);
}
try to check the script include is scope if your working on the same scope or calling from different scope.
Feel free to mark helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 12:42 AM
You are unnecessary making things complicated by writing glideAjax to just get consumer sys_id. Rather you can use getReference method with callback function. Use below script in client script and it will do job.
var con= g_form.getReference('parent', getConsumer);
function getConsumer(con) {
alert('consumer sys id = ' + con.consumer);
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 12:47 AM
Hi
he g_form.getReference() method requests the whole Record to the server. It may cause slowness to your Client Side action.
Best way to call from Server data is using GlideAjax API.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 02:11 AM
Hey Aman,
Yes, make sense.
@Siddharam if you need more field from that record then you can use getReference, if you need only one value then its better to go with GlideAjax.
Regards,
Abhijit
ServiceNow MVP