What is this error called "undefined" or "null"

Prathamesh Cha1
Tera Contributor

Hi all,

Can anyone tell me why this error is coming, here I am trying to fetch value of "value" field of record from "question_answer" table. 

 

PrathameshCha1_0-1698512570187.png

 

PrathameshCha1_1-1698512744128.png

 

 

10 REPLIES 10

OlaN
Giga Sage
Giga Sage

Hi,

Some minor adjustments to your script should do it.

Like this:

 

var date = new GlideRecord('question_answer');
// your query rows here
date.query();
if (date.next()){  // added parenthesis to the next function
	gs.info(date.getUniqueValue());  // gets the sysID
	gs.info(date.getValue('value')); // gets the "value" field
}

 

hi@OlaN ,

 

PrathameshCha1_3-1698520903527.png

 

in loop it is not printing anything outside it is printing but not the value

 

In this script you do the print both inside the loop, and outside (after the loop).

If there is no records matching your query, then this will happen.

First, there is the print in the loop, and because no records exists, there is nothing to print.

Then you try to print again after the loop, then the values used are not defined, so that becomes the "null" and "undefined" printouts.

Check your query and try again.

Also, correct your script and replace the following

gs.print(date.value)
// should instead be
gs.print(date.getValue('value'));

Jaspal Singh
Mega Patron
Mega Patron

Hi Prathamesh,

Script is fine. However only issue is the if clause. Update it as below

if(date.next()) from if(date.next)