none
Global Vs. Local Variables - Mapping

    Question

  • The situation:

    I am going from the source file and splitting the data across five tables which currently works great. The problem I am having is I need to generate an id that ties all the tables together and then reset that id for every file.

    I have created a C# class that keeps control of the variables and increments them for the destination which works great as well.

    The problem I am having is getting the variables to reset for every file. There is nothing being mapped that is unique to get the variables to reset per file. So I created a c# scripting functiod that did the incrementing thinking that it would reset it self since it a local function. The problem I am having with this is the counters are resetting themselves with every call so all of my counters are 1 and never increment.

    I have also tried resetting the global counters by calling a c# class that i created called ResetGlobalCounters and this just does not work.

    I am a programmer by trade and new to this biztalk stuff and I am having a real problem understanding how this orchestration and mapping uses and stores variables. I have several books but none of them get into real detail.

    Any suggestion would be much appreciated.

    Friday, March 27, 2009 12:53 PM

Answers

  • When you say reset it with the last element do you mean source or destination?

    Unlike most EDI mapping engines, the target side "drives" BizTalk mapping.  Understanding the flow is important.  For example, in this target LOOP

    LOOP
       REC
         ELE
       REC2
         ELE2

    1.  When are record node is encountered (LOOP, REC, REC2), any link that blocks the output, such as an
         Equal functoid connected to that node, is executed first.
    2.  Scripting attached to the record node is executed after all the children of that node have been executed.

    For example, you initialize a global counter at the beginning of your map to 0.  You increment the counter in a script connected to the LOOP node.  The value of the counter will be 0 for the first pass through REC, ELE, REC2, & ELE2, and will be incremented after these four nodes complete execution.

    Thus when you think of controlling the map, think of the DESTINATION side.

    Stepping through the code will be possible in 2009.  For the moment, you can look at the XSLT generated when you validate the map and see the flow of execution.  Learning XSLT is in our opinion, a prerequisite for mapping with BizTalk as some solutions require XSLT.

    Hope this helps







    Jim -- Pro Mapping in BizTalk 2009, Apress Books, March 23, 2009
    • Marked as answer by fsubob2004 Friday, March 27, 2009 7:40 PM
    Friday, March 27, 2009 2:46 PM

All replies

  • We cover this extensively in Pro Mapping in BizTalk Server 2009, which was just released by Apress.

    Without seeing your specific example it is hard to say what is wrong.  You may be able to fix this by manually resetting the variables in a Scripting functoid connected to the last target element processed for each file.  Examine the code generated when you validate your map and you may see that the reset is occurring at the wrong place.  BizTalk does not always generate the logic that you expect.

    Or, if you want, send me you map and schemas and I will take a look.

    jim@sspsi.com





    Jim -- Pro Mapping in BizTalk 2009, Apress Books, March 23, 2009
    Friday, March 27, 2009 2:22 PM
  • Thanks for the reply. We already have the book on order and look forward to going through the examples.

    When you say reset it with the last element do you mean source or destination?

    The problem I am having is there is not really a last element mapped as the every element I mapping repeats or is conditional.

    I wish there were an easy way to step through it to see the output.

    I also have a question in regards to the orchestration. I am calling a c# function to increment a trancation id and it sort of works the probems is it sometimes increments more than once per file. I assumed the orchestration was only hit once when the file came in... I guess I am mistaken? Is this covered in your book as well?

    Thanks
    Friday, March 27, 2009 2:31 PM
  • When you say reset it with the last element do you mean source or destination?

    Unlike most EDI mapping engines, the target side "drives" BizTalk mapping.  Understanding the flow is important.  For example, in this target LOOP

    LOOP
       REC
         ELE
       REC2
         ELE2

    1.  When are record node is encountered (LOOP, REC, REC2), any link that blocks the output, such as an
         Equal functoid connected to that node, is executed first.
    2.  Scripting attached to the record node is executed after all the children of that node have been executed.

    For example, you initialize a global counter at the beginning of your map to 0.  You increment the counter in a script connected to the LOOP node.  The value of the counter will be 0 for the first pass through REC, ELE, REC2, & ELE2, and will be incremented after these four nodes complete execution.

    Thus when you think of controlling the map, think of the DESTINATION side.

    Stepping through the code will be possible in 2009.  For the moment, you can look at the XSLT generated when you validate the map and see the flow of execution.  Learning XSLT is in our opinion, a prerequisite for mapping with BizTalk as some solutions require XSLT.

    Hope this helps







    Jim -- Pro Mapping in BizTalk 2009, Apress Books, March 23, 2009
    • Marked as answer by fsubob2004 Friday, March 27, 2009 7:40 PM
    Friday, March 27, 2009 2:46 PM
  • Wow!

    So Biztalk has an order of operations... did not know that. Is this discussed in your new book?

    I have been driving everything off of the source so that is part of my problem.

    So my destination consists of 5 tables that will all have this id I am incrementing in them. The question I have now is does biztalk insert one row in each tables as it goes through so i only have to increment the id on the first table and that same id will be added to the other tables as well or does it insert all the data to the first table then hit the second table and so on.

    We have our output creating correctly with the use of some looping functiods but we still are not sure its exact order.

    You have been a big help and thanks for responding so quick. I post stuff on biztalkgurus all the time an have yet to get a response to any question. If you know of any other good biztalk books let us know. We already have the other two you contributed on.

    Thanks
    Friday, March 27, 2009 3:27 PM