Unable to get property 'split' of undefined or null reference : Service Portal

arshanapalli
Tera Contributor

I see this error on some items in the service portal view. Any input on this is greatly appreciated:

find_real_file.png

 

 

1 ACCEPTED SOLUTION

ARG645
Tera Guru
If you have string say X which has Null value And you do x.split() You will get such types of error

View solution in original post

4 REPLIES 4

ARG645
Tera Guru
If you have string say X which has Null value And you do x.split() You will get such types of error

Thanks for the quick reply Aman. I get what you are saying and that triggers where I made my mistake.

ARG645
Tera Guru
arshanapalli,
Please close this thread if your question was answered. If its not, then please let me know your further questions.
Thank you,
Aman Gurram

williamhol
Kilo Explorer

This issue arises when js/jquery is not able to refer to the element. It is because at the time of rendering the page(view), object is null or undefined - which means that there is no instance of a class in the variable. If you are getting data for object from an async call(api's), these kind of problems will arise. So you should always check the object whether it is null or undefined then if it is not, you can access its properties.

The standard way to catch null and undefined simultaneously is this:

if (variable == null) {
// your code here.
}

Because null == undefined is true, the above code will catch both null and undefined.

Also you can write equivalent to more explicit but less concise:

if (variable === undefined variable === null) {
// your code here.
}

This should work for any variable that is either undeclared or declared and explicitly set to null or undefined.

In most cases this error is related to getElementById(). So getting a value from an input could look like this:

var value = document.getElementById("frm_new_user_request").value

Also you can use some JavaScript framework, e.g. jQuery, which simplifies operations with DOM (Document Object Model) and also hides differences between various browsers from you.

Getting a value from an input using jQuery would look like this:

input with ID "element": var value = $("#element).value
input with class "element": var value = $(".element).value