Cannot convert null to an object (scripts background)

robhaas
Tera Contributor

Very simply put, I am running a query in scripts background and am getting the error 'cannot convert null to an object'. I'm not sure which piece is pulling back null. Can anyone advise what I can change in the script?

The logs say the error is in line 5. - 'org.mozilla.javascript.EcmaError: Cannot convert null to an object.'

var gr = new GlideRecord('x_access_request');

gr.query();

while (gr.next()){

if (gr.getValue('receivers').contains(gr.getValue('opened_by'))) {

gs.print('Number : ' + gr.number);

gs.print('Requestor : ' + gr.opened_by);

gs.print('Receivers : ' + gr.getValue('receivers'));

}

}

TIA!

6 REPLIES 6

Bryan Tay3
Mega Guru
hi Robert,     it is probably line 05 that is having problem.   just verify gr.getValue('receivers') and/or   return something not null.   you can check it by     if (gr.next()) {         gs.print('Receivers: ' + gr.getValue('receivers')); }   before the while loop.   Hope this helps.

snehabinani26
Tera Guru

Hi Robert,



Please check the value in the field Receivers. Check whether the field name is correct, whether it contains any value. What kind of field it is.


robhaas
Tera Contributor

I ended up thinking about this and getting it to work prior to reading these posts. It was receivers causing the issue because there were null values. I got both !includes and !contains to work. Thank you both for your replies!


Hi Robert,



It would be great if you close the thread so it doesnot appears in unanswered list.