Wednesday, December 5

Adding logic to the table looping and table extractor functoids

I recently had an unusual request which involved using the table looping and table extractor functoids...

The problem is described below:

the source schema had a node similar to the one below

<BookingDetails reference="234" referencecode="FD453" creationdate="2011-10-11"/>

The idea was to create a repeatable node like the one below from this schema. Basically, if both reference and referencecode are passed in from the source, I need to create a new instance (in the destination schema) of the repeating node below for each of them, using the Instance attribute to show which one is mapped to each node as shown:

<ns1:BookingID Instance="ref" DT_Context="2011-10-11" ID="234" />
<ns1:BookingID Instance="refcode" DT_Context="2011-10-11" ID="FD543" />

Basically, if any of the reference and referencecode nodes is empty or null, the table looping functoid should not create a loop for that null or empty node

Of course, I could use xslt, but the table looping functoid and the table extractor functoids were used to solve the problem in a few seconds

The mapping solution goes as such:

  1. Add a table looping functoid to your map
  2. Add two table extractor functoids to the map
  3. Add the BookingDetails node as the first [0] input into your table looping functoid. This tells the functoid that this is the node from which the repeating structure will be created
  4. We are interested in 2 attributes (could also be nodes) because we want the table looping functoid to loop values based on reference and referencecode. Open up the table looping functoid and type in the integer 2 as the second [1] input to specify that we want two columns from the functoid
  5. Now add the attributes 'reference' and 'referencecode' as inputs [2] and [3] to specify that this is where the data for the first column will come from
  6. For inputs [4] and [5], type in the strings 'ref' and 'refcode' respectively to show that these will be thwe values in the second column
  7. Open the second (Table Looping) tab of the functoid.
  8. In row 1 column 1, select 'reference' as the first entry
  9. In row 1 column 2 select 'ref' as the entry
  10. In row 2 column 1, select 'referencecode' as the entry
  11. In row 2 column 2, select 'refcode' as the entry
  12. Tick the 'Gated' checkbox at the bottom of the tab to show that the first column will be used as the logical gate for the functoid, meaning that if any of the inputs in this column return nothing, the corresponding loop will not be created
  13. Drag a link to the BookingID node of the destination schema to show that this will be the repeating node
  14. Drag a link (as output) to the first table extractor functoid
  15. Drag a link (as output) to the second table extractor functoid
  16. Open up the first extractor functoid and type in the integer 1 as input [1] to show that this will extract the first row of the first column
  17. Open up the second extractor functoid and type in the integer 2 as input [1] to show that this will extract the second row of the first column
  18. Drag a link from the first extractor to the 'ID' attribute of the BookingID node in the destination to show that this output will be mapped to the 'ID' attribute in the repeating node
  19. Drag a link from the first extractor to the 'Instance' attribute of the BookingID node in the destination to show that this output will be mapped to the 'Instance' attribute in the repeating node
  20. Simply drag a link directly from the creationdate node on the source to the DT_Context node on the destination as this does not need to be passed into the table and will be created for every loop of the table
  21. Build the map
If you now test your map twice with two messages derived from the source schema with the BookingDetails node set as in the two examples below, you should get the  bookingID structures like the two outputs shown further down (one of them will not repeat)

Input BookingDetails nodes
Case 1
<BookingDetails reference="234" referencecode="FD453" creationdate="2011-10-11"/>

Case 2
<BookingDetails referencecode="FD453" creationdate="2011-10-11"/>


Repeating Output BookingID nodes
Case 1
<ns1:BookingID Instance="ref" DT_Context="2011-10-11" ID="234" />
<ns1:BookingID Instance="refcode" DT_Context="2011-10-11" ID="FD543" />
Case2
<ns1:BookingID Instance="refcode" DT_Context="2011-10-11" ID="FD543" />

 Hope this helps someone

No comments:

Post a Comment