I realize that this breaks most of (if not all) the architecture rules we've come to cherish, but sometimes it's just more efficient (easier) to place a “little” business logic in your maps.
If you recall from my previous posts, I've been working to integrate purchase orders and invoices between our Houston, TX and Glasgow, Scotland facilities. Since the ERP systems involved already handle the currency translation, I thought everything else would fall into place pretty simply. At first glance it did but after more extensive testing, several other “little” issues came to light that required a quick and dirty approach to handle in a timely manner. Which really means the boss gave me less than one hour to get it fixed!
The problem was really pretty simple: one ERP system wanted to place it's purchase orders and receive it's products in kilograms (KG) and the other ERP system wanted to receive it's sales orders and ship it's products in pounds (LB). Not really a problem in the “paper” world but definitely an issue in the “electronic” world.
I found the easiest way to handle this was with a simple Scripting Functoid using Inline C# code as shown below. If the inbound unit-of-measure for the item is in kilograms, the script converts it to pounds. If the UOM is anything else, it doesn't. Simple, clean and efficient!
public string ConvertQty(string strQty, string strUOM)
{
if(strUOM == "KG")
{
double dval = Convert.ToDouble(strQty,
System.Globalization.CultureInfo.InvariantCulture);
return (dval*2.205).ToString("F");
}
return strQty;
}