Cannot read property "0" from undefined

basantsoni
Kilo Guru

Hello Friends,

I’m facing error messages when we are reading and printing all array values from for loop.

I have stored true/false fields into array.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Basant,

this happens when you are trying to access something which has not that property

try below and check whether error comes or not

gs.info('Following Array Values : ' + gciscdP[checkboxes[i]]);

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Hi,

 Did you get any solution,let me know i am also facing similar kind off issue.

Hi Basant,

 Could you please check this once.

I am also facing similar kind of issue.

var add=gr.createDataSource(current,cei_number);
gs.log("outPut"+add);
var address = add.split('|');
gs.log("final address"+address);


//if(add.indexOf('PO Box')>-1||add.indexOf('P.O. Box')>-1)
if( add !='null' || add != undefined)
{

gs.log("first if");
var addre=address[0];
var str=addre.toString();
//var str=address[0].toString();

 

i am getting error when i read the address[0] value.

 

 

Thanks,

Uma.

Anurag Tripathi
Mega Patron
Mega Patron

I got this working

 

var cb=['number', 'short_description'];
var gr = new GlideRecord('incident');
gr.get('9d385017c611228701d22104cc95c371');
gs.print(gr[cb[0]]);

 

-Anurag

-Anurag

BhupeshG
Tera Guru

I am also getting the same error

 

Evaluator: org.mozilla.javascript.EcmaError: Cannot read property "0" from undefined
   Caused by error in script at line 12

      9: 		var nm = gr1.name;
     10: 		var len1=[];
     11: 		len1 = nm.split(' ');
==>  12: 		var cc = len1[0];
     13: 		var cod = new GlideRecord('u_country_code');
     14: 		cod.addQuery('u_code',cc);
     15: 		cod.query();

Hi Bhupesh,

check by printing the value of nm in logs

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader