What is this error called "undefined" or "null"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 10:05 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 10:41 AM - edited 10-28-2023 10:42 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 12:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 12:47 PM
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'));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2023 11:11 AM
Hi Prathamesh,
Script is fine. However only issue is the if clause. Update it as below
if(date.next()) from if(date.next)