Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Transform map date format error

Tanmay14
Tera Contributor

Hello,

 

I am pulling user related data from a SFTP source and one of the fields in staging table is called as HireDate. This is a string field and the date copied in this field has format 'yyyy-MM-dd', eg.: 2000-11-27. But the target table is sys_user where the target field is Start Date of type Date/Time which is of format 'MM-dd-yyy HH: mm: ss  z, eg.: 07-09-2024 12:15:48 AM.

 

Transform map is throwing error : Unable to format undefined using format string MM-dd-yyyy HH:mm:ss for field u_start_date.

 

I followed the steps as per KB https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0960405

This did not help resolve the error.

 

Kindly let me know how I can convert this date.

 

Thanks

 

2 REPLIES 2

Samaksh Wani
Giga Sage

Hello @Tanmay14 

 

Pls refer the below script :-

 

// Example input date string in 'yyyy-MM-dd' format
var dateString = '2000-11-27';

// Parse the input date string into a GlideDate object
var parsedDate = new GlideDate();
parsedDate.setDisplayValue(dateString);

// Format the parsed date into 'MM-dd-yyyy HH:mm:ss' format
var formattedDate = parsedDate.getDisplayValueInternal();

// Output the formatted date
gs.info('Formatted Date: ' + formattedDate);


Pls mark my solution as Accept, if you find it helpful.

Regards,

Samaksh Wani

Hi,

 

Thanks for your response. Your suggestion did not work for me. I managed to make it work with below logic:

 

var inputDate = source.u_hiredate;

var dateComponents = inputDate.split('-');

var year = dateComponents[0];

var month = dateComponents[1];

if (month.toString().length == 1)

    month = '0' + month;

var day = dateComponents[2];

if (day.toString().length == 1)

    day = '0' + day;

var formattedDate = month + '-' + day + '-' + year;

return formattedDate;