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 ?

7
  • 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
    Commented Nov 28, 2021 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
    Commented Nov 28, 2021 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
    Commented Nov 29, 2021 at 9:47
  • Are you sure it's failing on that functoid? The error message doesn't make that clear.
    – Ruud
    Commented Nov 29, 2021 at 12:49
  • I tested by removing the functoid and the transform works without it.
    – Davon
    Commented Nov 29, 2021 at 13:35

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.