Convert and populate date of String type to the Date type field using field map script(transform map

kamadi lokeshra
Tera Contributor
 
1 ACCEPTED SOLUTION

Hi @kamadi lokeshra 

 

Hope You Source string field value having specific format.

Create a On before  transform map script and add following snippet  (correct that date format as you want  as per your existing configuration)

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var dtObj = new GlideDate();
dtObj.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dtVar = dtObj.getByFormat("MM-dd-yyyy");
target.new_joining= dtVar;

})(source, map, log, target);

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

4 REPLIES 4

Tanushree Maiti
Tera Sage

Hi @kamadi lokeshra 

 

Here is the script:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var dtObj = new GlideDate();
dtObj.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dtVar = dtObj.getByFormat("MM-dd-yyyy");
target.actual_date= dtVar;

})(source, map, log, target);

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti ,

It is not working as expected. 
My source field is g_hiredate which is of string type and target field is new_joining which is of date type.

Hi @kamadi lokeshra 

 

Hope You Source string field value having specific format.

Create a On before  transform map script and add following snippet  (correct that date format as you want  as per your existing configuration)

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var dtObj = new GlideDate();
dtObj.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dtVar = dtObj.getByFormat("MM-dd-yyyy");
target.new_joining= dtVar;

})(source, map, log, target);

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti ,
It is working as expected after making the date format(as source date format) under the source field.
Thank you for your solution and for the quick response.