To store value in multiline text field using array

welcome
Kilo Contributor

Hi All,

                  I have a query in service catalog item. I have two multiline text field. In first field i am putting some values like 'test1-123'

                                                                                                                                                                                                                                                                                                                                                                            'test2-456'

                                                                                                                                                                                                                                                                                                                                                                              test3-789'

                  Now I want to split all these values by '-'. I want to set 'test1', 'test2' and 'test3' in one multi line text and '123' '456' '789' in another multi line text field.

                  I am able to split all the values but the problem is that I am not able to store all left side value(test1, 'test2', test3') in the first multi line text field

                  and right side value('123','456','789') in second   multi line text field.

                  Only last value which is 'test3-789' showing. that means     'test3' is coming on first   multi line text field and '789' is on second   multi line.

     

                                                I have done this coding in client script:-

function onLoad() {

var major = g_form.getValue('text1');

var value1=major.split('\n');

var value2=major.split(',');

alert("item length:"+value1.length);

for (var i=0; i < value1.length; i++) {

alert("Display value is: " + value1[i]);

   

alert("resp value length:"+value1[i].length);

resp = value1[i].split('-');

  var bs = resp[0];

  var ans1 = resp[1];

  g_form.setValue('text1', resp[0]);

  g_form.setValue('text2', resp[1]);

}

please help to resolve this problem. Thanks in advance.

Regards,

Payal Bharti

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Below should work



function onLoad() {


var major = g_form.getValue('text1');


var value1=major.split('\n');


var value2=major.split(',');


alert("item length:"+value1.length);


var bs=[];


var ans1=[];


var resp='';


for (var i=0; i < value1.length; i++) {


resp = value1[i].split('-');


  bs.push(resp[0]);


  ans1.push(resp[1]);



}


g_form.setValue('text1', bs);


  g_form.setValue('text2', ans1);


}


View solution in original post

6 REPLIES 6

Chandresh
Tera Guru

Hi Payal,



I had the same situation where there is a date variable and I split the date and set it in some variable. Hope below code will help


var ctesForm = g_form.getValue('required_by'); //lets say i put value 12-02-2016 in this variable


var date = ctesForm.split("-");


var abc = date[0];   //this will contain 12


var xyz = date[1]; //this will contain 02


var pqr = date[2]; // this will contain 2016


now you can push these variables in any field by setValue()




Hit Like/Helpful/Correct if this helps


Thanks Chandresh.


I   tried the same code but it is applicable only when I put one value ( 'test1-123') and not for multiple values. Could you please help me for multiple values.


srinivasthelu
Tera Guru

Below should work



function onLoad() {


var major = g_form.getValue('text1');


var value1=major.split('\n');


var value2=major.split(',');


alert("item length:"+value1.length);


var bs=[];


var ans1=[];


var resp='';


for (var i=0; i < value1.length; i++) {


resp = value1[i].split('-');


  bs.push(resp[0]);


  ans1.push(resp[1]);



}


g_form.setValue('text1', bs);


  g_form.setValue('text2', ans1);


}


Thanks Srinivas. I tried and it works fine. It is coming like that (test1,test2,test3) in first multi line text field and (123,456,789) in second multi line text field.


And i want this in this manner(in new line)


                                                            test1


                                                              test2


                                                              test3


                                                and 123(in second line)


                                                              456


                                                              789    


Can you please suggest how do I add a new line.