Skip to main content

IMPORTANT - Product End of Life Statement - IMPORTANT

Request RE, Survey, and Calendar 1.5 Support Ending December 31, 2020
Contact Kinetic Data Support with Questions
Kinetic Community

Using Date and Times with Task Handlers and Trees

Passing dates and times through Task Handlers may require you to use some specific formatting.



Date, Time, and DateTime Remedy fields (including fields referenced by @base and @dataset) are returned as Ruby Time objects (see<wbr/>core/classes/Time.html).  When passed to a Task Handler, objects are converted to Strings (by calling the #to_s method).  Ruby Time objects return strings in the format of "Thu Sep 01 12:04:35 -0500 2011" when #to_s is called.
Kinetic Request @answer values are always treated as Strings, so Date and Date/Time questions are stored as the date in a format called ISO8601, which looks like "2011-09-01T12:04:35-05:00".
To submit values into Remedy fields, you can either pass an ISO8601 string:
    'Date/Time Field' => "2009-04-17T03:13:00-05:00",
    'Date Field' => "2009-04-17",
    'Time Field' => "03:13:00"
or a Ruby time object:
    'Date/Time Field' => Time.parse('Thu Sep 01 12:04:35 -0500 2011')
Ruby Time objects have a nice helper method called #iso8601, which will return the ISO8601 string format.  They also have a method #parse, which will parse most valid Date/Time strings and return a Time object.
To use the @dataset['Last Modified Date'] (Modified Date - field 6 - you may need to add this to your data set) as the parameter for a handler, you need to use <%= @dataset['Last Modified Date'].iso8601 %> (which passes the ISO8601 string that ArsModels can write directly to the Remedy DateTime field).
To use a date/time from now, you would do something like this:
# Sets Scheduled Start Date to 10 minutes from now                
# Sets Scheduled End Date to 10 days from now                
@start_date = + 10                
@end_date = + (86400*10)                
@field_values['Scheduled Start Date'] = @start_date.iso8601                
@field_values['Scheduled End Date'] = @end_date.iso8601
   :field_values => @field_values


Here is a sample of the formatted output of various Date fields.

Parameter value to make a date  go into a date/time field in Remedy:


Format in node: 2011-09-08T20:33:00Z

Remedy Date Field (epoch value) - <%=@dataset['Last Modified Date']%>

Format in node: Thu Sep 08 15:33:53 -0500 2011

Remedy Date Field (epoch value) with iso8601 - <%=@dataset['Last Modified Date'].iso8601%>

Format in node: 2011-09-08T15:33:53-05:00

Parameter value to make a date  go into a date field in Remedy:

<%=  date = (Time.parse(@answers['Start Date'] + "T00:00:00Z")) 

Note you can put T06:00:00Z if you want it to be midnight eastern (to be sure it is the correct day) and so on for each time zone.

Here is a sample error message for the Remedy Date Field without the iso8601:

  ArsModels::Exceptions::ModelException: MessageType: 2
MessageNum: 1590
MessageText: Format of date or time value is not recognized.
AppendedText: "Thu Sep 08 15:33:53 -0500 2011": Date/Time Field


Parameter value to make a date/time human readable to go into a text field/email (this particular format would yield a date like 03/21/2016 9:37 AM:

<%=  date = (Time.parse(@answers['Start Date'])) 
date.utc.strftime("%m/%d/%Y %l:%M %p")%>
Details on ruby date formatting (the %m, etc part) can be found here.