Updating the date via background script shows the wrong date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 11:50 PM
I am trying to update the date for a custom field to test a notification
The date is updating wrong date and wrong format . Here is the below o/p
How to update in correct format ? Appreciate the Help
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 12:09 AM - edited 12-05-2023 12:15 AM
Hi @SAS21 ,
Put your new date to the GlideDateTime format:
var newDate = new GlideDateTime("2023-01-12 02:00:00");
var newDate = new GlideDateTime("2023-01-12 02:00:00");
var gr = new GlideRecord('u_incident');
gr.addEncodedQuery(' u_status=Pending');
gr.setLimit(1);
gr.query();
if(gr.next())
{
gr.setValue("u_pend_start_date",newDate);
gr.setWorkflow(false);
gr.autoSysfields(false);
gr.update();
gs.info('newDate' + newDate);
gs.info('pend date' + gr.u_pend_start_date);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 02:20 AM
Hello @SAS21,
Try this updated scripts -
var newDate = "12/01/2023 02:00:00";
var date = new GlideDateTine(newDate);
var gr = new GlideRecord('u_incident');
gr.addEncodedQuery(' u_status=Pending');
gr.setLimit(1);
gr.query();
if (gr.next()) {
var pendingStartDate = gr.u_pend_start_date.toString();
gr.setValue("pendStartDate", date);
gr.setWorkflow(false);
gr.autoSysfields(false);
//gr.update();
gs.info('newDate' + newDate);
gs.info('pend date' + pendStartDate);
}
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar