iCannot read properties of null (reading 'toLowerCase')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 08:37 AM - edited 05-29-2025 08:40 AM
Hi,
I am getting an error 'Cannot read properties of null (reading 'toLowerCase') on GlideAJAX. Kindly help.
GlideAJAX
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ci_name = newValue;
var ga = new GlideAjax('get_app_code');
ga.addParam('sysparm_name','getApplication');
ga.addParam('sysparm_ci',ci_name);
////
ga.getXML(getInfo);
}
function getInfo(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('ci_code1',answer.toLowerCase());
//alert(answer);
//Type appropriate comment here, and begin script below
}
Script Include
var get_app_code = Class.create();
get_app_code.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplication: function()
{
var ci = this.getParameter('sysparm_ci');
var gr = new GlideRecord('cmdb_ci_service_auto');
gr.addQuery('sys_id',ci);
gr.query();
if(gr.next())
{
return gr.u_application_code;
}
//gs.addErrorMessage(ci);
//return ci;
},
type: 'get_app_code'
});
Error: Unhandled exception in GlideAjax. Cannot read properties of null (reading 'toLowerCase')
Regards
Suman P.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 09:41 AM - edited 05-29-2025 10:03 AM
Can you add an alert(answer) before the g_form.setValue to see what the script include is returning.
Edit: You can also try g_form.setValue('ci_code1',answer.toString().toLowerCase());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 09:55 AM
Hello @Dave_p
The toLowerCase() method works only on string values.
Make sure the answer variable is of type string before calling toLowerCase() on it.
You can verify the type by adding:
alert(typeof answer);
This will help ensure you're not calling the method on an undefined or non-string value.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 09:55 AM
Hi @Dave_p ,
Update your script include like this (make sure it returns something
var get_app_code = Class.create();
get_app_code.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplication: function() {
var appCode = '';
var gr = new GlideRecord('cmdb_ci_service_auto');
if (gr.get(this.getParameter('sysparm_ci'))) {
appCode = gr.getValue('u_application_code');
}
return appCode ? appCode : '';
},
type: 'get_app_code'
});
client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('get_app_code');
ga.addParam('sysparm_name', 'getApplication');
ga.addParam('sysparm_ci', newValue);
ga.getXMLAnswer(getInfo);
}
function getInfo(answer) {
g_form.setValue('ci_code1', answer ? answer.toLowerCase() : '');
//alert(answer);
//Type appropriate comment here, and begin script below
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 09:59 AM
Most likely your client-side getInfo() function is trying to call .toLowerCase() on a null value, probably the Script Include (get_app_code) is not returning any value when the GlideRecord query doesn’t find a matching record — i.e., answer becomes null.
You can add an alert as Brian suggested to confirm or add a null check before calling toLowerCase()
function getInfo(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
g_form.setValue('ci_code1', answer.toLowerCase());
} else {
g_form.setValue('ci_code1', ''); // or show a message, or leave as-is
}
}