Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Issue with formatting date on target field via transform map

Steven Watts2
Tera Guru

Hi,

I'm trying to set 3 target fields on the Computer class which are all of type date via the SNOW transform maps. When the source data is transformed I was getting the error 'Unable to format 2028-11-10 using format string dd-MMM-yyyy for field u_refresh_date'. Same error for each of the fields. I therefore updated the date format in the field map to 'dd-MM-yyyy' which matches our system default. I tried setting the date format to ''dd-MMM-yyyy' but again got the error above.

When I loaded the data again the fields were populated but the date formatting was wrong. See below:

Date set - 

StevenWatts2_0-1691594897421.png

Date from source - 

StevenWatts2_1-1691595019431.png

I would therefore expect, am trying to set, the date would appear as 29-Jul-2028.

 

This is the source script:

 

 

answer = (function transformEntry(source) {

	var targetRefreshDate = (source.u_comp___refreshdate.getDisplayValue());
	return targetRefreshDate; 

})(source);

 

 

Anyone see where i'm going wrong?

Steven

3 REPLIES 3

Samaksh Wani
Giga Sage

Hello @Steven Watts2 

 

Use getByFormat();

 

 

Thanks for the suggestion @Samaksh Wani 

 

I've just updated the source script to:

 

answer = (function transformEntry(source) {

	var targetRefreshDate = (source.u_comp___refreshdate.getDisplayValue());
	formattedTargetRefreshDate = targetRefreshDate.getByFormat("dd-MMM-yyyy");
	gs.log("SNOW refresh formatted date - " + formattedTargetRefreshDate);
	return formattedTargetRefreshDate; 

})(source);

 

Will let you know once we're re-processed the data. 

 

Steven

Hello @Steven Watts2 

 

Plz mark my solution as Accept and give thumbs up, if you got any help from it.

Regards,

Samaksh