0

I have a map with a C# script in Script functoid to convert a date in dd/MM/yyyy format to yyyy-MM-dd format:

Here is the script I use in my functoid :

public string CheckDate(string inputDate)
{
  if(String.IsNullOrEmpty(inputDate))
    return "";
  else
  {
    System.DateTime dt = System.Convert.ToDateTime(inputDate);
    return dt.ToString("yyyy-MM-dd");
  }
}

For an unknow reason this script works perfectly when I do a Test Map in VS, it also works on my DEV environment but when I deploy it on UAT I got this error message:

General Exception : Error encountered while executing the transform XXX. Error:Transformation failed..

I already tried to use TryParse() or TryParseExact() but the mapping behavior is still the same. Work on DEV and Test Mapping but not on UAT.

EDIT

I catched the InnerException from Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.Convert.ToDateTime(String value) at System.Xml.Xsl.CompiledQuery.Script1.ConvertCompletedDate(String param)

So the issue is the input value but I only desn't work on UAT environment. This error is not thrown on DEV. I checked the .NET framework used and they are the same on both environment.

Can someone tells me how I can transform 18/11/2021 to a valid DateTime format ?

Davon
  • 121
  • 2
  • 9
  • And what is the value of inputDate? Have you checked the date/time settings on the UAT servers vs DEV. You might want to use the ToDateTime(String, IFormatProvider) overload to make sure that it is using the format you expect – Dijkgraaf Nov 28 '21 at 20:05
  • Also try putting a try/catch around it and output the inputDate as is in the catch block to help with debugging. – Dijkgraaf Nov 28 '21 at 20:17
  • InputDate value: 17/11/2021, I already log it for debugging purpose. The code I use in this scripting functoid is already in use on other mapping that are working fine on UAT so it's not an setting issue. I already tried ToDateTime(String, IFormatProvider), same error. The try/catch give no more information about the error. – Davon Nov 29 '21 at 09:47
  • Are you sure it's failing on that functoid? The error message doesn't make that clear. – Ruud Nov 29 '21 at 12:49
  • I tested by removing the functoid and the transform works without it. – Davon Nov 29 '21 at 13:35
  • The idea behind the try catch is then to write the date to the output field as is, maybe you aren't getting the value you expect. – Dijkgraaf Nov 29 '21 at 19:33
  • Also, please use the [edit] link to add details to the question. – Dijkgraaf Nov 29 '21 at 19:38

1 Answers1

0

I finally figured out that my TryParseExact() wasn't good.

If you have these kind of error and the issue concern a DateTime, the answer is the @Shar1er80 's reply here

Davon
  • 121
  • 2
  • 9