Convert Date/Time field to Date Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 01:53 AM
Hi All,
Can we convert Date/Time Field to Date Field? Can you please help me to understand the complications or issues here?
Thanks,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 02:01 AM - edited 11-02-2022 02:09 AM
Hi @kamma_priya
In ServiceNow, Changing the Data Type is not recommended and not best practice.
For existing data, it will lose your data also. Its always recommended to create new Date field, using Fix Script update the values of new Date Field using your old Date/Time field and than just make your old Date/Time field inactive.
Please find the code for Fix Script below:
var inc = new GlideRecord('incident');
inc.addEncodedQuery("u_schedule_date_timeISNOTEMPTY");
inc.query();
while(inc.next())
{
var schDT = new GlideDateTime(inc.u_schedule_date_time);
var SchDate = schDT.getDate();
inc.u_schedule_date = SchDate;
inc.update();
}
I used 2 fields here : Schedule Date/Time and Schedule Date. You can make changes based on your field and there field names.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023