- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2015 07:29 AM
I am developing a calculated field to be displayed on a page for each outage. Whenever I choose a date and time, the calculated field displays the value 5 hours off, likely an incorrect timezone. Here is an illustration of the difference:
My code looks like this:
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
if (current.end.nil())
{
current.u_detailed_message = current.cmdb_ci.name + ': ' + current.message + ' | Begin Time: ' + current.begin + ' | End Time: Unknown';
}
else if (!current.end.nil())
{
current.u_detailed_message = current.cmdb_ci.name + ': ' + current.message + ' | Begin Time: ' + current.begin + ' | End Time: ' + current.end;
}
}
Can anyone help correct this? It appears to be five hours off.
I have tried using code such as:
var tz = Packages.java.util.TimeZone.getTimeZone("America/Chicago");
var time = new GlideDateTime();
time.setTZ(tz);
time.setValue(current.begin);
time.setValue(current.end);
I used the "time.setValue(current.begin)" in the actual code where I concatenated the fields, but "undefined" displayed instead.
I am not sure which direction I should be headed. Anyone know how to deal with this?
I think I could possibly hard-code subtracting the 5 hour difference, but I don't like the idea.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2015 12:01 PM
Hi Gregcoogan,
In the first code what you pasted just append getDisplayValue() to the date field what you are fetching. I.e
current.begin.getDisplayValue()
Corrected one is below current.u_detailed_message = current.cmdb_ci.name + ': ' + current.message + ' | Begin Time: ' + current.begin.getDisplayValue() + ' | End Time: Unknown';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2015 12:01 PM
Hi Gregcoogan,
In the first code what you pasted just append getDisplayValue() to the date field what you are fetching. I.e
current.begin.getDisplayValue()
Corrected one is below current.u_detailed_message = current.cmdb_ci.name + ': ' + current.message + ' | Begin Time: ' + current.begin.getDisplayValue() + ' | End Time: Unknown';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2015 12:08 PM
Thank you! It worked. I don't know how I missed that!