- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 05:39 AM
Hey folks,
I need some help if you can spare me a few minutes.
I'm doing an import of Servers and we are trying to acquire the "Last Boot" time, which is being monitored.
I have a regular "String" field in SN.
and i'm trying to import a date. I'm having an issue because SN keeps detecting it as a date/time and transforming it to GMT.
I have tried getting the value of the field,and doing a toString(), putting it in the string field. No worky.
and date/time fields are still very confusing to me the way scripts need to be run in order to get the accurate time for you timezone, because of the date/time always being in GMT.
Can anyone help me with a script for my Timezone and to account for Daylight Savings Time?
The import field looks like so:
9/9/2009 12:00:00 PM
4/10/2015 11:59:00 AM
1/12/2016 8:16:00 PM
1/14/2016 5:40:00 PM
the import transforms it to:
4/1/2014 1:12:00 AM >>>>>>>>>>> 2014-04-01 05:12:00
var boot = source.u_last_boot;
target.u_last_boot = boot;
I have looked at the wiki but dont understand how to write a script that looks at current timezone, accounts for daylight savings time, and give me my localtimezone value.
But more importantly, i dont understand why SN has to turn a string going to a string, into a date/time value?
I'm currently in Eastern US time zone.
My system time is Eastern US time zone.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 07:49 AM
Steven,
The behavior you are describing sounds to me like the import set data table is set up as a date/time field. When you create a new data source for your import set, ServiceNow looks at the data you are importing and tries to identify the data type. If you look at the Data Source for this import set it lists the Import Set Table name. Look up that table in the Tables & Columns list and see if the last boot field is set to a date/time. If that is set to a date/time, then you will need to change it to a string value.
My question to you is, why don't you want it as a date/time value? It is much easier to sort or run reports on date/time information that is actually stored as a date/time value. If the field you are putting the data in was a date/time field, you shouldn't have to do anything with your values. ServiceNow is already converting your import information to GMT time, which is how it stores date/time values and if that is put into a date/time field, it will automatically convert that to your local time zone when it is displayed.
-Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 06:20 AM
Hi Steven,
Since the target field is a date time field and the field in which you are storing the incoming date time is a string, it is behaving in this way. Is the field in which you are storing the incoming value a date/time field?
You can specify the format in the field map such as mm-dd-yyyy or yyyy-mm-dd. This helps in transforming whatever value is coming into the target table. This field map should not be affected with the time zone. You can check the same.
Mark Correct if this solves your issue or hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 06:46 AM
No. the field i'm trying to import to is a "String" field.
i set it as a string field because i thought that SN would leave the data along and just import what i wanted to import.
i'm getting a date/time from a field on the import.
turning it into a toString()
importing into a "string" field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 07:12 AM
to manually take of 4 hours, i'm doing the following.
var boot = source.u_last_boot; | |
var boottime = new GlideDateTime(boot); | |
boottime.subtract(14400000); | |
target.u_last_boot = boottime; |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2016 07:34 AM
Also set the time zone to your current time zone.
var boottime = new GlideDateTime(boot);
boottime.setTZ(gs.getSession().getTimeZone());
boottime.subtract(14400000);
target.u_last_boot = boottime.getValue();