Copy one message into another

Home Page Forums BizTalk 2004 – BizTalk 2010 Copy one message into another

Viewing 3 reply threads
  • Author
    Posts
    • #20427

      Hi all

      I have a message called msgOrder.
      I want to copy it to another message like so:

      msgOrderCopy = msgOrder; 

      This builds fine and I can deploy it.
      But when I run the orchestration it always fails.
      When I debug I see that the msgOrderCopy is blank. It is always NULL – it never gets assigned any data and this causes my system to fail because I am referencing the data a little later like so:
      msgOrderCopy.ponumber = “123”

      As I understand it you can copy one message into another.
      Any ideas why I cannot get this message to contain any data?

      Cheers
      TIA 

    • #20432

       Are you doing the copying the message within a construct message block?

      P.S. Once the construct message block finishes, the message is immutable.  You can’t make any changes after the construct block.

      • #20438

        You should also bear in mind context properties when copying one message to another – I made a bit of a wah some time ago (http://www.modhul.com/2007/10/29/so-what-does-msg2-msg1-do-exactly/).

        However, there is no reason why the copy isn’t copying… As ruselw points out, are you performing the copy (and later distinguished field assignment) within the same Construct Message block?

        Nick.

        Update: Whoops, that should have been *promoted property* assignment….

    • #20439

       Hello

      Thanks for the responses.
      Yes I am doing it all inside the same construct block.
      In fact here is my real – non obfuscated – code

       

      System.Diagnostics.EventLog.WriteEntry(“1″,”1”);
      msgEDIRebateCopy = msgEDIRebate;
      System.Diagnostics.EventLog.WriteEntry(“2″,”2”);
      msgEDIRebateCopy(Rebate.PropertySchema.CompanyNumber) = 905;
      System.Diagnostics.EventLog.WriteEntry(“3″,”3”);
      msgEDIRebateCopy(Rebate.PropertySchema.EDIDocumentNumber) = 22;
      System.Diagnostics.EventLog.WriteEntry(“4″,”4”);
      msgEDIRebateCopy(Rebate.PropertySchema.EDIBatchNumber) = 546;
      System.Diagnostics.EventLog.WriteEntry(“5″,”5”);

       

      So what I have done is write out a number to the eventlog at each stage of the operation so that I can tell where it is failing.
      It gets as far as the number “2” being written and then it fails.
      If I run it through the Orchestration debugger I see that “msgEDIRebate” is a full XML document but even once I have moved passed “2”,”2″ line I see that msgEDIRebateCopy is NULL – it never gets populated.

      BTW the construct block is set to construct the msgEDIRebateCopy message.

      TIA 

       

       

       

    • #20440

       I fixed it !!!!!! [:D]

      First of all thank you to the responses above. I followed the link and determined that I had to copy the CONTEXT as well as the message.
      So my new code looks like this:

      System.Diagnostics.EventLog.WriteEntry(“1″,”1”);
      msgEDIRebateCopy = msgEDIRebate;
      msgEDIRebateCopy(*) = msgEDIRebate(*);
      System.Diagnostics.EventLog.WriteEntry(“2″,”2”);
      msgEDIRebateCopy(Rebate.PropertySchema.CompanyNumber) = 905;
      System.Diagnostics.EventLog.WriteEntry(“3″,”3”);
      msgEDIRebateCopy(Rebate.PropertySchema.EDIDocumentNumber) = 22;
      System.Diagnostics.EventLog.WriteEntry(“4″,”4”);
      msgEDIRebateCopy(Rebate.PropertySchema.EDIBatchNumber) = 546;
      System.Diagnostics.EventLog.WriteEntry(“5″,”5”);

      And voilla it now makes it all the way to number 5.

      If you are interested and have time read on:

      There are currently 2 projects in the solution. “Claims” and “Rebates”.
      The Claims project always existed from before I started here.
      When I joined I was asked to create a “rebates” project.
      It is identical to the claims in every way except that
      1) It would have a different namespace and
      2) The schema would have 2 extra fields (RebateType and RebateValue)

      I was told to copy the Claims project EXACTLY – only change variable names etc to match rebates.
      So I did this. Eg: The message copy code is taken verbatim from claims – it does not have any CONTEXT copying and yet it works fine.

      Weird!

      • #20441

        Sounds like you weren’t copying across the promoted properties, so they didn’t exist in the copied message, hence the runtime exception (although it would compile fine as the copied message schema would let you select them in the Expression Shape).

        If you’re happy with the solution, mark it as the answer!

        Cheers, Nick.

Viewing 3 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.