Issue with dates on an inbound email action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 11:14 AM
I'm trying to take a date from an inbound email and set that as a catalog variable which has a type of date but when I do this no matter what date I set in the email the variable always gets set as the current date.
The email contains Hire date: 01/07/2023 for example:
This is the inbound email action:
But this is the result I get:
Any suggestions on how best to take a date from an email and just have it populate on a date variable.
Kind regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 11:40 AM
Hi @Alex Saager1 ,
Hope you are doing great.
Use below script in inbound action to populate hire date in start date :
var hire_date = email.body.hire_date;
var hire_date_obj = new GlideDateTime(hire_date.toString());
cart.setVariable(item,'start_date',hire_date_obj );
Fore reference go through GlideDateTime API
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/c_APIRef
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:16 PM
Hello Riya,
Thank you for the info, I've added your script to my inbound action but unfortunately get the same result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:21 PM - edited 06-23-2023 12:23 PM
@Alex Saager1 , you are setting start date in intital as below syntax:
cart.setVariable(item,'start_date',hire_date_obj );
Then there is no need to set the start date again at line 19, please comment line 19 and then try.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:30 PM
Thank you @Riya Verma
That seems to have worked but it's swapped the month and day around, just as an FYI my system settings are set as dd/mm/yyyy