How to combine 2 array fields?

Zod
Giga Guru

Hi,

for a string I can do something like this ... current.u_field1 =   current.u_field1 + current.u_field2; current.update();

... but how to do this if both fields are arrays?

Thank you!

1 ACCEPTED SOLUTION

Have a read of this thread about why not to use current.update()



Never use current.update in a Business Rule



try the below script, it's saying, if the current watch list is not empty, get the value and add it to the work notes.



if(!current.watch_list.nil()){


var watch = current.getValue('watch_list');


current.work_notes_list += ',' + watch;


}


View solution in original post

16 REPLIES 16



It really depends what you need to do, if you just need to populate one list with another you can use getValue() and setValue():



var list1 = current.getValue('u_list_1');


current.setValue(u_list_2', list1);



if you need to add a value you ca   use +=



current.u_list_1 += ',' + current.u_reference_1;



These are, i guess, simpler options but listUtils offers more utility.


This looks more like what I was looking for, but does not seem to work.


I tried:



var newVar = current.getValue('u_field2');


current.setValue('u_field1',newVar);


current.update();


Where are you configuring this? An after update business rule? If you're changing values on the current form you should use a before update BR and don't use current.update(). Both of these list fields are on the same form right?



I just tested from a fix script and the below worked out fine.



var gr = new GlideRecord("incident");


gr.addQuery("number", "INC0236943");


gr.query();


if (gr.next()) {


var work = gr.getValue('work_notes_list');


gr.setValue('watch_list', work);


gr.update();


}


OMG - forget the current.update() !



... yes is BR before update.



Anyhow - not working.



IF you are on an incident and you would like to move all people from watch_list and add the to the people already in the work_notes_list ... this would fit close to what I need to achieve ...


Have a read of this thread about why not to use current.update()



Never use current.update in a Business Rule



try the below script, it's saying, if the current watch list is not empty, get the value and add it to the work notes.



if(!current.watch_list.nil()){


var watch = current.getValue('watch_list');


current.work_notes_list += ',' + watch;


}