length() & trim() function giving error

lakshmi_p
Kilo Explorer

Hi everyone,

I am using length() & trim() in client script, but receiving this error. Please suggest how to work on this.

find_real_file.png

find_real_file.png

Regards,

Lakshmi Patel

1 ACCEPTED SOLUTION

zac
Mega Contributor

Would this work?



if(answer != null && answer.length == 15)



Good luck!


View solution in original post

11 REPLIES 11

zac
Mega Contributor

My pleasure


Shahed Shah1
Tera Guru

Hi Lakshmi



When you get an error like this, it suggests that the answer object is null (be aware that the actual error can vary from browser to browser). Meaning that there is most likely no response being received from your Ajax response.



You could include some code to prevent the error, for example


if (answer) {


        if (answer.length == 15) {


                  //... code comes here


        }


}



or even


if (answer && answer.length == 15) {


        //... code comes here


}



Either way, you need to test the answer object. So alerting the value of answer would be a good step to see if you are getting a response.



However this is only a workaround. If you don't have a result being returned when you are expecting to, then you would need to shift your debugging to the respective server-side code (most likely a Script Include). Add some gs.log() statements and use Session Debug to inspect what is happening (or not happening) during its execution.



While I'm here, is there a reason why you are doing this synchronously? Should you get this working and end up bringing back a big response, this will cause the browser to lock up. Would it be too much to follow the guidance of using GlideAjax - ServiceNow Wiki (so don't make it synchronous)?



Regards


Shahid