Today's functoid addresses another classic "scripting" problem within the BizTalk Mapper.

Often when mapping I find that I am being given dates in an established format (often "yyyyMMdd" the EDI standard) and need to translate that date into another format used by the destination schema (usually "MM/dd/yyyy").  A perfectly reasonable thing to need to do within a data transformation engine.  Normally this would take a scripting functoid when done correctly (when done incorrectly it can involve a dozen or more string functoids).  This functoid will add to the Conversion group and take three parameters, the first is a date, the second is the format in which the date is currently formatted, and the third is the desired format of the date.

For those more interested in the .NET than the functoid, you will note I used the little known DateTime.ParseExact in this functoid.  This requires us to provide an IFormatProvider.  Since BizTalk is a service, I opted to use the System.Threading.Thread.CurrentThread.CurrentCulture.  The other option would have been CurrentUICulture, but that could provide very strange results.

Download TimRayburn.CustomFunctoids v1.0

   10     class FormatDateFunctoid : BaseFunctoid
   11     {
   12         public FormatDateFunctoid()
   13         {
   14             // Assign a "unique" id to this functiod
   15             this.ID = 24604;
   17             // Setup the resource assembly to use.
   18             SetupResourceAssembly(
   19               "TimRayburn.CustomFunctoids.CustomFunctoidsResources",
   20               Assembly.GetExecutingAssembly());
   22             SetName("IDS_FORMATDATEFUNCTOID_NAME");
   23             SetTooltip("IDS_FORMATDATEFUNCTOID_TOOLTIP");
   24             SetDescription("IDS_FORMATDATEFUNCTOID_DESCRIPTION");
   25             SetBitmap("IDB_FORMATDATEFUNCTOID_BITMAP");
   27             this.SetMinParams(3);
   28             this.SetMaxParams(3);
   30             SetExternalFunctionName(this.GetType().Assembly.FullName,
   31               "TimRayburn.CustomFunctoids.FormatDateFunctoid",
   32               "FormatDate");
   34             this.Category = FunctoidCategory.Conversion;
   35             this.OutputConnectionType = ConnectionType.AllExceptRecord;
   37             AddInputConnectionType(ConnectionType.AllExceptRecord);
   38             AddInputConnectionType(ConnectionType.AllExceptRecord);
   39             AddInputConnectionType(ConnectionType.AllExceptRecord);
   40         }
   41         public string FormatDate(string inDate, string inFormat, string outFormat)
   42         {
   43             System.Globalization.CultureInfo ci = 
   44               System.Threading.Thread.CurrentThread.CurrentCulture;
   45             DateTime lDate = System.DateTime.ParseExact(inDate, inFormat, ci);
   46             return lDate.ToString(outFormat,ci);
   47         }
   48     }