Convert Strings to Numbers in a Functoid

Convert Strings to Numbers in a Functoid

As shown in my previous posts, I have been tackling some messy maps in Visual Studio for our BizTalk solution. I inherited some confusing and broken source code, and am just now getting it all to work!

One of the issues I was having was mapping both the begin dates and the end dates of a record, by using the cumulative minimum or the cumulative maximum of dates. The source system sends dates as a string, in the YYYYMMDD format. When I tried to take the cumulative max or min, I would consistently get no data. I could map without the cumulative functoids, but that does not follow our business rules.

Question: What was causing my cumulative max/min functoids to blow up?

Cause: Cumulative maximum and cumulative minimum functoids only consistently work with numeric values, and not strings. See: http://msdn.microsoft.com/en-us/library/aa561894(v=bts.10)

Solution: Custom string-to-numeric scripting functoid.

Scripting_Convert_Numeric

Here’s how it works. The scripting functoid gets the date from the source xml, converts it to a number, and then the cumulative max/min functoid works like a charm. Once the date is parsed via the string extract functoids, and reformatted in the string concatenate functoid, it is back in its string format. Here is the code in my scripting functoid:

public Int32 ConvertDatetoInt(string param1)
        {
                return System.Convert.ToInt32(param1);
        }

Pretty simple, quite nifty.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s