Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Convert string to date field

matt_a
Kilo Guru

I have been having issues with a date field being passed into ServiceNow via a transform.

the date in the SQL table reads dd/mm/yyyy.

When the data populates into the import set, there are various issues.

I deleted the field on the import set table and ran another load of data in. This recreated the field as a string field and has corrected all of the issues I was seeing.

The problem is now transforming this into my user records.

If I set the transform map to read the field as dd-mm-yyyy i get the error:

Unable to format dd/mm/yyyy using format string dd-MM-yyyy for field u_dob

I think I am going to need a script to convert the string? But I have not been very successful to date and have tried several variations based on community posts. But nothing appears to work!

1 ACCEPTED SOLUTION

dvp
Mega Sage

Use the following script in field map and see if it works

var gdt = new GlideDateTime(source.u_field_name); // UPdate the field name to date field name on import set table
return gdt.getDate();

View solution in original post

5 REPLIES 5

ss52
Tera Contributor

Hi dvp,

 

I am reopening the long post. I also have similar kind of requirement.

 

We receive a string from Splunk integration into servicenow. The value in the string which comes from Splunk is like this 2020-09-17T15:45:22.000+00:00

 

I need to convert this in to date and time

 

I have used the script which u have posted.

var gdt = new GlideDateTime(source.u_field_name); // UPdate the field name to date field name on import set table
return gdt.getDate();

By using this i am just getting only date but not time.

 

Could you please help with this requirement.

 

Thanks