All I want to do is to copy and paste values from one column to another column...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 03:41 PM
I know that many people have asked similar questions before, but I have no choice but to pose it again, because ServiceNow is refusing to execute any script I wrote, no matter how I modify them. (ノಥ益ಥ)ノ ┻━┻
I'm developing an app that is essentially a sign-up sheet for work stations. At this point, I'm creating a Daily Script Execution that updates the sign-up sheet by moving the (current+1) day's reservations to the current day, moving the (current+2) day's reservations to the (current+1) day, etc., regardless whether a field is empty or not.
All "Reservation" columns have the type "Reference".
These are my codes for the Daily Script Execution:
// This SSE moves D-day+1's reservations to the D-day
// And clears the D-Day's & D-Day+30's reservations
// At 00:00:00 every day
var gR = new glideRecord('x_123456_work_st_1_list_of_work_stations');
gR.query();
while (gR.next()) {
// D -> 0
gR.clearValue('reservations_current_day');
gR.update();
// D+1 -> D
var reserv_dDay_1 = g_form.getValue('reservations_current_day_1');
g_form.setValue('reservations_current_day', reserv_dDay_1);
gR.update();
// D+2 -> D+1
var reserv_dDay_2 = g_form.getValue('reservations_current_day_2');
g_form.setValue('reservations_current_day_1', reserv_dDay_2);
gR.update();
// D+3 -> D+2
var reserv_dDay_3 = g_form.getValue('reservations_current_day_3');
g_form.setValue('reservations_current_day_2', reserv_dDay_3);
gR.update();
// D+4 -> D+3
var reserv_dDay_4 = g_form.getValue('reservations_current_day_4');
g_form.setValue('reservations_current_day_3', reserv_dDay_4);
gR.update();
// D+5 -> D+4
var reserv_dDay_5 = g_form.getValue('reservations_current_day_5');
g_form.setValue('reservations_current_day_4', reserv_dDay_5);
gR.update();
/*
The rest of the codes will be completes
once the existing codes start working properly
*/
g_form.clearValue('reservations_current_day_30');
gR.update();
}
I tried both gR.setValue()
and g_form.setValue
, but neither worked.
I tried both gR.clearValue()
and g_form.clearValue
, but neither worked.
Any help would be greatly appreciated!
- Labels:
-
Scripting and Coding
-
Studio

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 04:17 PM
Hi,
I assume your script is server-side when you want to run it on a schedule
Try this
- corrected spelling of GlideRecord
- changed g_form to gR
- updating just at the end
- removed the initial clean up of D, no need to empty if you assign value in the next step
If it does not help just clarify where and how is your script being executed.
var gR = new GlideRecord('x_123456_work_st_1_list_of_work_stations');
gR.query();
while (gR.next()) {
// D+1 -> D
var reserv_dDay_1 = gR.getValue('reservations_current_day_1');
gR.setValue('reservations_current_day', reserv_dDay_1);
// D+2 -> D+1
var reserv_dDay_2 = gR.getValue('reservations_current_day_2');
gR.setValue('reservations_current_day_1', reserv_dDay_2);
// D+3 -> D+2
var reserv_dDay_3 = gR.getValue('reservations_current_day_3');
gR.setValue('reservations_current_day_2', reserv_dDay_3);
// D+4 -> D+3
var reserv_dDay_4 = gR.getValue('reservations_current_day_4');
gR.setValue('reservations_current_day_3', reserv_dDay_4);
// D+5 -> D+4
var reserv_dDay_5 = gR.getValue('reservations_current_day_5');
gR.setValue('reservations_current_day_4', reserv_dDay_5);
/*
The rest of the codes will be completes
once the existing codes start working properly
*/
gR.setValue('reservations_current_day_30','');
gR.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 08:41 AM
It's starting to work!
Now I just need to figure out how to make it work when a fiels's value is null
.
Thank you so very much for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2022 12:23 AM
Cedric,
how do you mean it?
Even if it is null, the null value moves same as if there was an actual value.
Can you give me an example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2022 09:03 AM
Yes, sir, I can.
// D+1 -> D
var reserv_dDay_1 = gR.getValue('reservations_current_day_1');
if (reserv_dDay_1 == null) {
gR.setValue('reservations_current_day', '');
}
if (reserv_dDay_1 != null) {
gR.setValue('reservations_current_day', reserv_dDay_1);
}
// D+2 -> D+1
var reserv_dDay_2 = gR.getValue('reservations_current_day_2');
if (reserv_dDay_2 == null) {
gR.setValue('reservations_current_day_1', '');
}
if (reserv_dDay_2 != null) {
gR.setValue('reservations_current_day_1', reserv_dDay_2);
}
// D+3 -> D+2
var reserv_dDay_3 = gR.getValue('reservations_current_day_3');
if (reserv_dDay_3 == null) {
gR.setValue('reservations_current_day_2', '');
}
if (reserv_dDay_3 != null) {
gR.setValue('reservations_current_day_2', reserv_dDay_3);
}
// D+4 -> D+3
var reserv_dDay_4 = gR.getValue('reservations_current_day_4');
if (reserv_dDay_4 == null) {
gR.setValue('reservations_current_day_3', '');
}
if (reserv_dDay_4 != null) {
gR.setValue('reservations_current_day_3', reserv_dDay_4);
}
As you can see, I had to create two conditional statements, because the system wouldn't copy and paste the null
from one column to the other.