Display Biztalk Date to String

I am working on a biztalk project and use the map to create a new message.

Now I want to match the date feed to a string.

I thought I could do it using the Script function with inline C #

public string convertDateTime (DateTime parameter) {return System.Xml.XmlConvert.ToString (param, ÿyyyMMdd); }

But this does not work, and I get an error message. How can I do the conversion on the map?

This is a Biztalk 2006 project.

+4
source share
5 answers

Without the detailed error information you see, it's hard to be sure, but I'm sure your card is not working, because all parameters in the BizTalk XSLT processor are passed as lines 1 .

When I try to run something like the function that you provided as embedded C #, I get the following error:

An object of type "System.String" cannot be converted to a type of "System.DateTime"

Replace your inline C # with something like the following:

public string ConvertDateTime(string param1) { DateTime inputDate = DateTime.Parse(param1); return inputDate.ToString("yyyyMMdd"); } 

Note that the parameter type is now a string, and you can then convert it to DateTime and execute your string format.

Like other answers, it might be better to include this helper method in an external class - this way you can get your code under the test to deal with edge cases and also use some reuse.


1 The fact that all parameters in BizTalk XSLT are strings can be the source of many errors - another common with mathematical calculations. If you return the numerical values ​​from your functoids scripting functions, BizTalk will help you convert them to strings to match them with the outgoing schema, but it won’t perform very random rounding of the resulting result values ​​so efficiently. Converting returned values ​​to strings in C # will eliminate this risk and give the expected results.

+2
source

If you use a cartographer, you just need the scripting functionality (yes, using the built-in C #), and you can do this:

 public string convertDateTime(DateTime param) { return(param.ToString("YYYYMMdd"); } 

As far as I know, in any case you do not need to name the System.Xml namespace.

+1
source

Given that the cards in BizTalk are implemented as XSL stylesheets, when transferring data to the msxsl script msxsl note that the data will be one of the types in the Equivalent .NET Framework Class (Types) from this table here . You will notice that System.DateTime not listed.

For parsing xs:dateTime s, I usually got the /text() node and then parsed the parameter from System.String :

 <CreateDate> <xsl:value-of select="userCSharp:GetDateyyyyMMdd(string(s0:StatusIdChangeDate/text()))" /> </CreateDate> 

And then c # script

 <msxsl:script language="C#" implements-prefix="userCSharp"> <![CDATA[ public System.String GetDateyyyyMMdd(System.String p_DateTime) { return System.DateTime.Parse(p_DateTime).ToString("yyyyMMdd"); } ]]> 
0
source

I suggest

 public static string DateToString(DateTime dateValue) { return String.Format("{0:yyyyMMdd}", dateValue); } 

You can also create an external Lib that provides greater flexibility and reusability:

 public static string DateToString(DateTime dateValue, string formatPicture) { string format = formatPicture; if (IsNullOrEmptyString(formatPicture) { format = "{0:yyyyMMdd}"; } return String.Format(format, dateValue); } public static string DateToString(DateTime dateValue) { return DateToString(dateValue, null); } 

I try to move every function that I use twice inside the inline script to an external lib. Iit will give you well-tested code for all cross cases that your data can provide, since it allows you to create tests for these external lib functions, while it is difficult to do good testing of built-in scripts on maps.

0
source

This blog will solve your problem.

http://biztalkorchestration.blogspot.in/2014/07/convert-datetime-format-to-string-in.html?view=sidebar

Regards, AboorvaRaja Bangalore +918123339872

0
source

All Articles