Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Custom Date Functiod
- This topic has 5 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
January 18, 2010 at 7:00 AM #24083
Hi all,
I would like to create a custom functoid for my mapping needs that would access a date value and return a Date in other format. The input element is string. This string contains the value of invoice date. Now i need to map this string value to Date element which data type is simple date.
The map should be on two elements, in source the element data type is string and in destination the element data typs is SimpleDate. I need the output in particular Date format. I am using BizTalk 2004.
Can any one guide me on this….
Thanks in advance.
Mike.
-
January 18, 2010 at 3:19 PM #24089
The easiest place to start is probably the sample Custom Functoid:
C:\Program Files\Microsoft BizTalk Server 2006\SDK\Samples\XmlTools\CustomFunctoid
-
January 19, 2010 at 5:00 AM #24092
Do you really want to buil a custom functoid? You could use the script functoid, and script .Net code.
-
January 19, 2010 at 10:15 AM #24094
The code below is for a custom functoid that I wrote to accomplish what you are asking. It takes two parameters in, date and format. It will use the DateTime.Parse() method to convert the date parameter to a DateTime type. It will then convert the date back to a string based on the .NET DateTime.ToString() formatting pattern specified in the format parameter. All of the standard .NET formatting patterns will work plus I added an extra to output Julian day by using “jjj” in the pattern.
Please let me know what you think!
[code]
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;
using System.Globalization;
using System.Resources;namespace BizTalk.CustomFunctoid
{
public class DateFormat : BaseFunctoid
{
static ResourceManager resmgr = new ResourceManager(“Meritain.BizTalk.CustomFunctoid.CustomResource”, Assembly.GetExecutingAssembly());public DateFormat()
: base()
{
// This has to be a number greater than 6000
this.ID = System.Convert.ToInt32(resmgr.GetString(“IDS_DATEFORMAT_ID”));
this.SetupResourceAssembly(“Meritain.BizTalk.CustomFunctoid.CustomResource”, Assembly.GetExecutingAssembly());//Set Resource strings , bitmaps
this.SetName(“IDS_DATEFORMAT_NAME”);
this.SetTooltip(“IDS_DATEFORMAT_TOOLTIP”);
this.SetDescription(“IDS_DATEFORMAT_DESCRIPTION”);
this.SetBitmap(“IDS_DATEFORMAT_ICON”);// Minimum and maximum parameters that the functoid accepts
this.SetMinParams(2);
this.SetMaxParams(2);// Function name that needs to be called when this Functoid is invoked.
// Put this in GAC
this.SetExternalFunctionName(GetType().Assembly.FullName, “Meritain.BizTalk.CustomFunctoid.DateFormat”, “FormatDate”);//Category for this functoid
this.Category = FunctoidCategory.DateTime;//Input and output Connection type
this.OutputConnectionType = ConnectionType.AllExceptRecord;
this.AddInputConnectionType(ConnectionType.AllExceptRecord);
}public String FormatDate(String dateIn, String formatOut)
{
String dateToFormat = dateIn.Trim();
DateTime theDate;
String dateFormatted = String.Empty;try
{
// Try to parse the date string passed through the map. /* .DayOfYear.ToString(“000”) */
theDate = DateTime.Parse(dateToFormat);dateFormatted = this.ApplyFormatting(theDate, formatOut);
}
catch
{
try
{
// “yyyyMMdd” cannot be parsed so try to format the date string to “MM/dd/yyyy” and reparse if parsing fails.
CultureInfo nfo = new CultureInfo(“en-US”);
theDate = DateTime.ParseExact(dateToFormat, “yyyyMMdd”, nfo);dateFormatted = this.ApplyFormatting(theDate, formatOut);
}
catch
{
dateFormatted = String.Empty;
}
}
return dateFormatted;
}private String ApplyFormatting(DateTime d, String f)
{
String s = String.Empty;// Check for lonely Julian Day and assign it to return value
if (f.Equals(“jjj”))
{
s = d.DayOfYear.ToString(“000”);
}
else
{
// Insert Julian Day where specified in date format string
s = d.ToString(f);
if (f.Contains(“jjj”))
s = s.Replace(“jjj”, d.DayOfYear.ToString(“000”));
}return s;
}
}
}[/code]
-Dave
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.