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

Your log says updates 425,

It means it updated the 425 entries because all the record already exists from previous imports.

Its not creating new ones as its updating each record by matching the fields.

Try to first clean/delete the records in that temporary source table then import and execute the transform map

Regards,
Anshu

There are about 20,000+ records so, I did not proceed to clean or delete the records. But ran the Transform Map next day and it worked.

find_real_file.png