"gr.getValue()" and "gr.getByFormat('hh:mm:ss')" return different times
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 01:56 PM
Hi Team,
I am drafting the below script to extract the HH:MM:SS from a date/time field for mapping to other fields ---
However, I'm seeing a 12-hour discrepancy. Please observe the attached snip [PFA-1].
Can anyone help me understand why there are two different times returned by '.getValue' and '.getByFormat' respectively? This is the target field[PFA-2].
var ct = new GlideRecord('u_coverage_tickets');
ct.addQuery('sys_id','004f3a4587c34154eaf041d8cebb3546'); //COT0001758
ct.query();
gs.log("CT-test " + ct.getRowCount());
if (ct.next()){
var gdt = new GlideDateTime(ct.u_previous_task_date);
gt = gdt.getTime();
gs.info(" value is " + gt.getValue()); // *** Script: value is 1970-01-01 17:00:00
gs.info(" time is " + gt.getByFormat('hh:mm:ss')); // *** Script: time is 05:00:00
}
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 09:47 AM - edited 11-17-2023 09:48 AM
Hi @PB7
I’m not sure why getTime() is not working. Maybe your table is in a scoped app?
Alternate:
var ct = new GlideRecord('u_coverage_tickets');
ct.addQuery('sys_id','004f3a4587c34154eaf041d8cebb3546'); //COT0001758
ct.query();
gs.log("CT-test " + ct.getRowCount());
if (ct.next()){
gs.addInfoMessage((ct.u_previous_task_date.toString().split(‘ ‘))[1]);
}
Thanks!
Please mark this response as correct and helpful if it works 👍✔️
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 09:55 AM
I can see you’re using gs.addInfoMessage on last line.
Try gs.info(gdt.getTime());
Thanks!
Please mark this response as correct and helpful if it works 👍✔️