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-28-2022 02:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 01:57 PM
Technically, yes, I was getting an error with the following codes:
var reserv_dDay_1 = gR.getValue('reservations_current_day_1');
gR.setValue('reservations_current_day', reserv_dDay_1);
If reservations_current_day_1
(current day + 1) is null
, but reservations_current_day
(current day) isn't, reservations_current_day
would not be replaced by null
.
However, after I added the "if" statements, as follows:
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);
}
Everything began working normally, whether reservations_current_day_1
(current day + 1) is null
or not.