
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:34 AM
Hi,
We have a catalog item with a variable "required_date" which we would like to map to the Due Date field on the catalog task that gets raised. However the required_date variable is type date, and the due_date field on sc_task table is type date/time.
In the workflow create task script we have "task.due_date = current.variables.required_date;"
This will populate a custom date field, but not the oob date/time field, but we would rather not go down the route of having a custom field to manage this.
Can anyone advise how to do this please.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 09:12 AM
Hi,
Using the numeric value, as suggested by Harsh870, is not a valid solution, since the due date on [sc_task] is expecting a Date/time value.
Try something like this in your script:
var date = current.variables.required_date;
var gdt = new GlideDateTime(date);
if (gdt.getValue() != ''){
task.setValue('due_date', gdt.getValue());
}
else {
task.setValue('due_date', new GlideDateTime()); // if no valid date is given, set current date as default
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 08:47 AM - edited 10-18-2023 08:49 AM
Hello @Cirrus ,
Use this script for your query, it will change your date as Date/Time format.
var myDate = current.variables.required_date;
var gdt = new GlideDateTime();
gdt.setDisplayValue(myDate);
var finalDate = gdt.getNumericValue();
task.due_date = finalDate;
Please mark as helpful and solution accepted if you got your answer. 👍

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 09:12 AM
Hi,
Using the numeric value, as suggested by Harsh870, is not a valid solution, since the due date on [sc_task] is expecting a Date/time value.
Try something like this in your script:
var date = current.variables.required_date;
var gdt = new GlideDateTime(date);
if (gdt.getValue() != ''){
task.setValue('due_date', gdt.getValue());
}
else {
task.setValue('due_date', new GlideDateTime()); // if no valid date is given, set current date as default
}