Thursday, March 16, 2006

You can evaluate dates using the
Cumulative Maximum Functoid

Dates you say? Stop the press! Hoist the mizenmast!

I had a situation where there was a node whose max occurs is unbounded and I needed to extract a single node from it to map to a destination node whose max occurs is one.

The problem was that I had to choose the node to map with the highest (newest) date:
<root>
<data>
<testdate>01-01-2000<testdate>
<testdata>a<testdata>
</data>
<data>
<testdate>01-01-2002<testdate>
<testdata>c<testdata>
</data>
<data>
<testdate>01-01-2001<testdate>
<testdata>b<testdata>
</data>
</root>

In the case above, I want the node with the highest <testval>, or 01-01-2002, therefore I want to map <testdata>c<testdata> to the destination node.

This can actually be done.

What I did was convert my date to ticks in a scripting functoid:

public string toTicks(string param1)
{
DateTime dt = DateTime.Parse(param1);
return dt.Ticks.ToString();
}

Afterwards I connected the scripting functoid to the cumulative max functoid.

Then I evaluate the output of the scripting functoid with the cumulative max functoid with an Equals functoid.

This should work for any set of repeating dates.

2 comments:

Anonymous said...

Do you happen to know how to include import statements into a vb scripting functoid? I want to create a sqlConnection, so need to import System.Data.SqlClient, but "Imports System.Data.SqlClient" gives me the error code bc30002. I also tried "open script tag"%@ import Namespace="System.Data.SqlClient" %"close script tag", but this gave an error that a character was not valid.
Any help would be most appreciated...

Lex Hegt said...

Hi Anonymous,

First my apologies for reacting so late. We've been quite busy lately.
Now about your issue:
Keep in mind that Inline scripts are best used, when it is unlikely that the code will be used anywhere else in your application. Otherwise it is better to create an assembly (which can be called from the Scripting functoid) or create a Custom functoid (which can be used in other maps as well).
Further: what exactly is your goal? Just having a SQL Connection in a mapper functoid provides no extra value, so I suppose you want to get data from a SQL Server database.
Why don't you use the Database lookup functoid instead?

Regardless from which namespace from the .NET framework you want to use, it would be handy if namespaces could be imported in the scripting functoid. Here's something about it.
Since the Inline scripts are stored in a XSLT sheet (which defines the map), a number of
namespaces are supported by default. These are the same namespaces as for any other XSLT stylesheet, namely:
System, System.Collection, System.Text, ystem.Text.RegularExpressions, System.Xml, System.Xsl, System.Xml.Xpath and Microsoft.VisualBasic.

Like you I a tried to import the namespace using the Imports-statement, I tried it without the Imports-statement (Dim myConn as ystem.Data.SQLClient.SQLConnection) and I tried it in the XSLT-manner by adding msxml-tags in the XML-file from the mapper. I tried the same kind of tricks in C# as well.
Nothing worked. Other namespaces than the ones I mentioned are simply not useable in this context.

Which leaves us to create an assembly, which can be called from the scripting functoid or to create a Custom functoid.