- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 11:26 PM
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::
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;
}
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 12:23 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 11:40 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2019 11:51 PM
Hi Manas,
No luck. I still see only one record inserted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 12:23 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 07:44 AM
Thanks. It worked.