Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to insert multiple records to same field

Hari1
Mega Sage

Hi,

I am not able to pass multiple values on to the same field.

I need to create multiple records with the below questions. But only one record is created. 

REF::

find_real_file.png

Can any help me out?

function getResponseValues(responseVal)
{
alert("Inside getResponseValues");
var getResponse = responseVal.responseXML.documentElement.getAttribute('answer');	
	
questions = JSON.parse(getResponse);

// I am able to see the values passed from script include but i am not able to set the values to the field

alert("question1: " + questions.var1);
alert("question2: " + questions.var2);
alert("question3: " + questions.var3);
alert("question4: " + questions.var4);
alert("question5: " + questions.var5);

//u_question is the same field i need to insert 4 records to the same field with different values

g_form.setValue('u_question',questions.var1); 
g_form.setValue("u_question",questions.var2);
g_form.setValue("u_question",questions.var3);
g_form.setValue("u_question",questions.var4);
g_form.setValue("u_question",questions.var5);

}

 

Script include::

var ResponseValues = Class.create();
ResponseValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	Response:function() 
	{
	var data;
	gs.log("Inside ResponseValues");
		
	var questionOne = "ABC";
	var questionTwo = "XYZ";
	var questionThree = "SGA";
	var questionFour = "QGS";
	var questionFive = "IHS";
	
	var questions = {};
	var gr = new GlideRecord('u_result');
	gs.log("Inside If");
	
	gr.initialize();
	gr.u_question = questionOne;
	gr.u_question = questionTwo;
	gr.u_question = questionThree;
	gr.u_question = questionFour;
	gr.u_question = questionFive;
	gr.insert();
	
	questions.var1 = questionOne;
	questions.var2 = questionTwo;
	questions.var3 = questionThree;
	questions.var4 = questionFour;
	questions.var5 = questionFive;
	
        data = JSON.stringify(questions);
	return data;
}
});
	
1 ACCEPTED SOLUTION

Hi 

You are inserting only one record by using following code.

 

var gr = new GlideRecord('u_result');

gr.initialize();

gr.u_question = questionOne;

gr.u_question = questionTwo;

gr.u_question = questionThree;

gr.u_question = questionFour;

gr.u_question = questionFive;

gr.insert();

 

If you want multiple records then try following.

 

var questions = 'ABC,XYZ,SGA,QGS,IHS';

var splitted = questions.split(',');

 

var gr = new GlideRecord('u_result');

for(var i = o ; i < splitted.length ; i++)

{

gr.initialize();

gr.u_question = splitted[i];

gr.insert();

}

 

View solution in original post

4 REPLIES 4

Manas Kandekar
Kilo Guru

Hi

If you want to set multiple values in same field then concatenate values and push in single field.

g_form.setValue('u_question',questions.var1 +', '+questions.var2+', '+questions.var3+', '+questions.var4+', '+questions.var5);

Hi Manas,

No luck. I still see only one record inserted.

Hi 

You are inserting only one record by using following code.

 

var gr = new GlideRecord('u_result');

gr.initialize();

gr.u_question = questionOne;

gr.u_question = questionTwo;

gr.u_question = questionThree;

gr.u_question = questionFour;

gr.u_question = questionFive;

gr.insert();

 

If you want multiple records then try following.

 

var questions = 'ABC,XYZ,SGA,QGS,IHS';

var splitted = questions.split(',');

 

var gr = new GlideRecord('u_result');

for(var i = o ; i < splitted.length ; i++)

{

gr.initialize();

gr.u_question = splitted[i];

gr.insert();

}

 

Thanks. It worked.