Copy Field value to another

venkatkk
Tera Contributor

Copy one field to another field in the list

In request i have a field called A and B   and also C and D

these A B C D fields are not visisble in the form , only on the list for reporting purpose.

A and B is a reference field

C and D is a String field

Now A and B has already some values for the request i want to copy the same value to C and D

ie A to be copied to C

      B to be copied to D

find_real_file.png

In the above screenshot I want to update the Location B (String) with the same value of Location (reference) and Region B(string) with the same value in Region (reference). I want to update the existing records in the list layout.

I want to update the old records , run a background script to do this. How can we approach

1 ACCEPTED SOLUTION

Try this script.Check whether the field names are correct or not.



addlocation();


function addlocation() {


var gr = new GlideRecord('sc_request');


gr.query();


while (gr.next()) {


gr.u_location_b = gr.u_location.getDisplayValue();


gr.u_region_b = gr.u_region.getDisplayValue();


gr.update();


}


}



Thanks,


Mihir


View solution in original post

9 REPLIES 9

a_anshu
Giga Expert

Hi Venkat,



You can do this by using a client script onSubmit,


Suppose the name of location   is loc and that of region is reg.



Now write a script to save the values of them in variables.



var location = g_form.getValue('loc');


var region = g_form.getValue('reg');



Thus you will get the values of location and region, now similarly you can set the value to locA and regB.



g_form.setValue('locA', location);


g_form.setValue('regB', region);



Hope it helps,


Abhinav



Please like, mark helpful or correct as per the impact.


Mihir Mohanta
Kilo Sage

Hi Venkat,


1.Write a business rule of before insert type that will update the string fields with reference fields.(Use getDisplayValue() function because reference type field stores sys_id value) .


2.For existing records, run background script.



Thanks,


Mihir


Thanks Mihir


I'm trying for the Old records but couldn't able to do it in background script any help pls


Please share the background script you have written.


Thanks,


Mihir