Mapping a date variable to date/time field

Cirrus
Kilo Sage

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.

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

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
}

 

View solution in original post

2 REPLIES 2

Harsh_Deep
Giga Sage
Giga Sage

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

OlaN
Giga Sage
Giga Sage

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
}