We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to get multiple field value of one field using get method.

Hari1
Mega Sage

Hi,

I need to get the field value of "question_text"

var grIncident = new GlideRecord('question');
returnValue = grIncident.get('8cdb154adb094810bda4d602ca961984');	
returnValue = grIncident.get('940bd50adb094810bda4d602ca9619ca');
returnValue = grIncident.get('c64f3e3ddb014810bda4d602ca961961');

gs.log(returnValue); // logs true or false
gs.log(grIncident.question_text); // logs question value

With the above script i am getting only the question value of "c64f3e3ddb014810bda4d602ca961961" but i need all 3 values.

1 ACCEPTED SOLUTION

SatheeshKumar
Kilo Sage

try the below code to get all the three values 

var grIncident = new GlideRecord('question');

var questions =[];
var returnValue =[];

returnValue.push( grIncident.get('8cdb154adb094810bda4d602ca961984'));
questions.push(grIncident.question_text+'');

	
returnValue.push(grIncident.get('940bd50adb094810bda4d602ca9619ca'));
questions.push(grIncident.question_text+'');	
returnValue.push(grIncident.get('c64f3e3ddb014810bda4d602ca961961'));
questions.push(grIncident.question_text+'');	

gs.log(returnValue.toString()); // logs true or false
gs.log(questions.toString()); // logs question value

 

But I'm not sure on which use case you are applying this!!

 

-Satheesh

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron

Hi Hemanth,

Can you share the complete script here?

Update code as below; query for all the sys_ids and then print the value

also the table which holds the survey questions is survey_question_new; so query with this table

var grIncident = new GlideRecord('survey_question_new');
grIncident.addQuery('sys_id','IN','8cdb154adb094810bda4d602ca961984,940bd50adb094810bda4d602ca9619ca,c64f3e3ddb014810bda4d602ca961961');
grIncident.query();
while(grIncident.next()){

gs.info(grIncident.question_text);

}

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

SatheeshKumar
Kilo Sage

try the below code to get all the three values 

var grIncident = new GlideRecord('question');

var questions =[];
var returnValue =[];

returnValue.push( grIncident.get('8cdb154adb094810bda4d602ca961984'));
questions.push(grIncident.question_text+'');

	
returnValue.push(grIncident.get('940bd50adb094810bda4d602ca9619ca'));
questions.push(grIncident.question_text+'');	
returnValue.push(grIncident.get('c64f3e3ddb014810bda4d602ca961961'));
questions.push(grIncident.question_text+'');	

gs.log(returnValue.toString()); // logs true or false
gs.log(questions.toString()); // logs question value

 

But I'm not sure on which use case you are applying this!!

 

-Satheesh

It worked. Thanks a lot.. 🙂