Using variable to set due date on task ticket - date is setting to the variable - 1 day. Why?

NancyS1
Tera Expert

I have a Due Date field on my catalog form, named csc_due_date. In the workflow on the Create Task activity, I'm using the due date on the task ticket. I'm using this script:

task.due_date = current.variable_pool.csc_due_date;

The due date field gets updated, but it's off by a day. For example, if I pick 1/15/2022 as my due date on the form, the ticket gets a due date of 1/14/2022. 

I don't understand why I'm off by a day. Any help appreciated.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

possibly because of timezone

use this

task.due_date = new GlideDateTime(current.variable_pool.csc_due_date);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@Naresh_5120 

Can you please post a new question and tag me there as this is older thread

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Maharshi Chatte
Kilo Guru

Hi,

As Ankur said this can be a timezone issue. We also faced this issue a number of times because by default the script takes the system timezone  . If you want you can change your timezone also from your profile and check once because we also did the same.

Regards,

Maharshi

NancyS1
Tera Expert

I'm afraid my mistake was in not noticing the catalog field was a Date field while the Due Date field on the task ticket is a Date/Time field. Once I changed the field type, I was able to use Ankur's code: 

 

task.due_date = new GlideDateTime(current.variable_pool.csc_due_date);

 

Thanks for the help!

@NancyS 

Did you mistakenly marked your own response as correct?

Would you mind marking my response as correct if I was able to help you.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader