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

This is the script i'm trying to run



addlocation();


function addlocation() {


var gr = new GlideRecord('sc_request');


gr.query();


while (gr.next()) {


gr.autoSysField(false); // so that the records don't have system updates


gr.setWorkflow(false); // so no business rules are run


gr.u_location = gr.u_location_b;


gr.u_region = gr.u_region_b;


gr.update();


}


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


I can see the field updated BUT getting error in script



Evaluator: org.mozilla.javascript.EcmaError: "RP" is not defined.


  Caused by error in script at line 4



  1: addlocation();


  2: function addlocation() {


  3: var gr = new GlideRecord('sc_request');


==> 4: gr.query();


  5: while (gr.next()) {


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


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



Evaluator: org.mozilla.javascript.EcmaError: "RP" is not defined.


  Caused by error in script at line -1


Evaluator: org.mozilla.javascript.EcmaError: "RP" is not defined.


  Caused by error in script at line 8



  5: while (gr.next()) {


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


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


==> 8: gr.update();


  9: }


  10: }


Glad to hear that script works.


Dont know why that error comes.There is no "RP" present in any line of the script.



Thanks,


Mihir


Might be it came from other value defined in my instance:(


Anyway whatever i needed works good BUT takes almost 10 secs to update 25 records. i have totally of 10000 records to update. Will it affect anything ...Any tuning can be done in this script?