How to parse inbound email date value formatted in yyyy-mm-dd to ServiceNow date variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 07:16 PM
Hi There,
We are receiving inbound mail to ServiceNow having date mentioned in the format "Date of Joining: 2024-06-29" (yyyy-mm-dd).
and we are trying to convert using below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 12:31 AM
Hi @Community Alums ,
Could you please provide some screenshots of the issue and the field where you want to set the date/time?
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 10:43 AM
Hi there @Community Alums
Guess u can use the following script to ensure proper conversion
var emailDate = "2024-06-29"; // Extracted date from the email
var dateParts = emailDate.split("-");
var formattedDate = dateParts[1] + "/" + dateParts[2] + "/" + dateParts[0];
var DOJ_obj = new GlideDateTime();
DOJ_obj.setDisplayValue(formattedDate);
This script splits the inbound date string, reorders it to the mm/dd/yyyy format required by GlideDateTime, and then sets it as a date object. guess this will nmake correct date is picked up by the system.
If this helps kindly accept the answer. thanks
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India