- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 08:18 AM
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
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:12 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:34 AM
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: }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 10:44 AM
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?