- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 08:54 AM
I am trying to update some cmn_schedule_span objects (move them forward one day). I understand that start_date_time and end_date_time are the fields I need, but these are of type GlideScheduleDateTime but stored as strings. However, I seem unable to create a 'regular' GlideDateTime which has has nice functions for addition to dates. This is roughly what I am trying to achieve:
var cmn_schedule_span = new GlideRecord('cmn_schedule_span');
cmn_schedule_span.addQuery('schedule', my_cmn_schedule_object);
cmn_schedule_span.query();
while(cmn_schedule_span.next()){
cmn_schedule_span.start_date_time.addDays(1);
cmn_schedule_span.update();
}
while(cmn_schedule_span.next()){
var start = new GlideDateTime(cmn_schedule_span.start_date_time);
start.addDays(1);
cmn_schedule_span.start_date_time = start.toString();
cmn_schedule_span.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2022 04:40 AM
Hello Kevin,
Could you please check with below script:
var cmn_schedule_span = new GlideRecord('cmn_schedule_span');
cmn_schedule_span.addQuery('schedule', cmn_schedule);
cmn_schedule_span.query();
while(cmn_schedule_span.next()){
var startDateTime = cmn_schedule_span.getDisplayValue("start_date_time");
gs.print("START DATE: " + startDateTime);
var gdt = new GlideDateTime();
gdt.setDisplayValue(startDateTime);
gdt.addDays(1);
var newDate = gdt.getDate();
gs.print("NEW DATE: " + newDate);
cmn_schedule_span.start_date_time = gdt.getDisplayValue();
cmn_schedule_span.end_date_time = gdt.getDisplayValue();
cmn_schedule_span.update();
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 11:51 PM
Hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
regarding the Z at the end to datetime value I tried using different approach but it is not coming, not sure why.
Thanks