Date/time input setup for different action item types
-
- UpdatedFeb 1, 2024
- 3 minutes to read
- Washington DC
- Mobile Configuration and Navigation
After you create an input form screen and define its IncludeTimezone attribute for date/time inputs, you must associate the input form screen with an action item. How you set up the date/time inputs depends on the type of action item you use.
Action item type | Set up |
---|---|
New or Update | Make sure that date/time inputs are mapped to date/time fields in the back-end instance. The back-end instance uses the Device Time Zone information sent by the input form screen. Then the back-end instance converts the date/time value to Coordinated Universal Time (UTC/GMT) before saving it to the database. |
Script | You must convert the date/time input value to UTC/GMT. Refer to the following script
examples for more information. For more information about scripting in general for ServiceNow, see Scripting
Note: Customizations might be needed depending on the use case
involved. |
GlideDateTime script example
The following example sets fields of the GlideDateTime type.
- In this example, the
expected_start
andestimated_end
fields are edited based on the values of their corresponding date/time inputs ofexpectedstart
andestimatedend
. - Because the IncludeTimezone attribute is set to true, the
parm_input.expectedstart
variable returns a date/time string in the format YYYY-MM-DDThh:mm:ss.sssTZD. To enable the system to handle this date/time format, initialize a GlideDateTime object by passing the string into the constructor. - Because
expected_start
andestimated_end
are Date Time columns in the database, you can directly call GlideRecord.setValue() and pass theGlideDateTime
object as the value.
GlideScheduleDateTime script example
The following example sets fields of the GlideScheduleDateTime type.
- In this example, the
start_date_time
andend_date_time
fields of a schedule entry are set based on the values of their corresponding date/time inputs ofstart_time
andend_time
. - Because the IncludeTimezone attribute is set to
true, the
parm_input.start_time
variable returns a date/time string in the format YYYY-MM-DDThh:mm:ss.sssTZD. To enable the system to handle this date/time format, initialize aGlideDateTime
object by passing the string into the constructor. - Because
start_date_time
andend_date_time
are not Date Time Columns in the database (instead, they are Schedule Date/Time columns), their value are set withgr.start_date_time = {date_time_value}
.Note: Thedate_time_value
is expected to be in the User Profile Time Zone (the value provided is expected to be theDisplay Value
of aGlideDateTime
). This configuration makes it possible to call the GlideDateTime.getDisplayValueInternal() method, which returns a date/time string in the internal format of YYYY-MM-DD hh:mm:ss and in the User Profile Time Zone.