Why getDate() is not working properly?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 01:07 AM
Hi all,
I've a requirement where I have to capture the record created date in another field without time attached. Simply, in OOB we have Created field which stores record created date and time as well. But I just need to capture the record created date without time in another field.
I've created the following script to capture the date in new field(u_created_date) which is a Date type field.
while(gr.next()){
var caseCreationDate = gr.getValue("sys_created_on");
var gd = new GlideDateTime(caseCreationDate);
gr.setValue("u_created_date",gd.getDate());
gr.update();
}
On executing the above script only some fields are giving me the right date. Some fields are giving wrong date.
Why it is happening like that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 02:52 AM
Hi,
try to identify which records are being shown with the previous day date?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 03:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 04:38 AM
that might be the pattern
try this
while(gr.next()){
var caseCreationDate = gr.sys_created_on;
var gd = new GlideDateTime();
gd.setValue(caseCreationDate);
gr.setValue("u_created_date",gd.getLocalDate());
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 07:27 AM
Hi Ankur,
Thanks for your time. I've implemented my requirement using Calculate value related list method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 09:04 AM
If your query is resolved then close the thread by marking appropriate response as correct.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
