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

Check with logs if no luck, then

try in your PDI instance with your same import set.

I don't know what is missing for you.

Regards,
Anshu

Suresh K1
Tera Contributor

Sure, thanks I will give it go in my PDI.

I tried in PDI, and it worked.

I am unable to figure out why it does not work in Dev instance. I will try to recreate the Column and see if it helps.

find_real_file.png

Yes sure try to recreate

There could be something missing maybe.

Regards,
Anshu

I deleted the column (WhenCreated) and created again in the source and target tables, ran the Transform, it does not work ... weird and mysterious. 

Here is the import log:

in the log, it seems like it is converting the string to date and time, but somehow it does not get updated in the target field. I cannot figure out what am I missing.

find_real_file.png