Issue with dates on an inbound email action

Alex Saager1
Tera Contributor

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:

AlexSaager1_0-1687543791336.png

 

This is the inbound email action:

AlexSaager1_1-1687543845266.png

 

But this is the result I get:

AlexSaager1_2-1687543893763.png

 

Any suggestions on how best to take a date from an email and just have it populate on a date variable.

 

Kind regards,

 

Alex

 

 

 

 

 

 

 

6 REPLIES 6

Riya Verma
Kilo Sage
Kilo Sage

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

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hello Riya,

 

Thank you for the info, I've added your script to my inbound action but unfortunately get the same result:

AlexSaager1_0-1687547354017.png

 

AlexSaager1_1-1687547377223.png

 

@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.

 

 

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

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

AlexSaager1_0-1687548551509.png

AlexSaager1_1-1687548598061.png