Convert Active Directory field (WhenCreated) value to Date and Time format in a Transform Map

Suresh K1
Tera Contributor

Dear Now Community Experts,

Context: Using a Transform Map, I am importing Active Directory (AD) data into a ServiceNow CMDB table.

Requirement: Convert the field value of' 'WhenCreated' (from AD) to a Date/Time format (in ServiceNow).
Sample value of 'WhenCreated' = 20181107064109.0Z

I tried the following sample script and it seems working.
---------------------------------------------------------
var d = '20181107064109.0Z';
var gdt = new GlideDateTime();
gdt.setValueUTC(d, 'yyyyMMddHHmmss');
gs.print(gdt.getDisplayValue());
---------------------------------------------------------
Script output: 

*** Script: 07-11-2018 14:41:09
------------------------------------
Note: UTC time is converted to my local time (UTC+8)

Now, I would like to use this script to run on a "Field Map" in the Transform Map
so that the target field is updated in 'Date/Time' format. I tried the following script with no success.
---------------------------------------------------------
find_real_file.png
Could you please help me in correcting the script ?

Kind regards
Suresh
1 ACCEPTED SOLUTION

Anshu_Anand_
Kilo Sage
Kilo Sage

 

I tried same scenario using data source and import set and its working

data source:-

find_real_file.png

 

Transform map field script

find_real_file.png

It works as you see below it created in the table.

data type is date/time for timing field i created just now.

find_real_file.png

check you code , if issue persists, try using logs to see what is wrong

If this is helpful, mark answer as correct

Regards,
Anshu

View solution in original post

11 REPLIES 11

Anshu_Anand_
Kilo Sage
Kilo Sage

 

I tried same scenario using data source and import set and its working

data source:-

find_real_file.png

 

Transform map field script

find_real_file.png

It works as you see below it created in the table.

data type is date/time for timing field i created just now.

find_real_file.png

check you code , if issue persists, try using logs to see what is wrong

If this is helpful, mark answer as correct

Regards,
Anshu

Please direct me to the location of logs. Is it the syslog in servicenow?

Suresh K1
Tera Contributor

Hi Anshu,

Thanks very much for the quick response and verifying the script that it is working for you. I corrected my code as per your script and tried running the transform map, but no luck.

I am not sure if the field type on the target table may be causing the issue for me. My field type is - Date/Time. 

What is the field type you set for your 'Timing' column?

Please ignore, I didnt read your message fully, you already mentioned that it is date/time type.