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

Community Alums
Not applicable

Hello there,

try something like

gciscpD['checkboxes[i]']

or gciscdP[newVar], where newVar is taking the checkboxes[i] value into the loop.

 

for(i in checkboxes){
   newVar = checkboxes[i];
   gciscpD[newVar];
}

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

Hi Ankur, 

Thanks for your valuable response, your solution always works for me.

thanks for your support and Help.

 

Thanks,

Basant

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();

can you please what is wrong here?