BizTalk Server: N1 Loop Mapping

BizTalk Server: N1 Loop Mapping


Introduction

It is very common scenario to map values from a loop in the applications where EDI X12 schemas are used and one of them is N1 Loop. Loops are nothing but blocks of repeating data. And N1 loop is such block which has address related data (Party Identification).  

It is not mandatory and in the schema which ships with BizTalk, allows it to repeat 
up-to 200 times (EDI schema  are shipped in as a self-extracting executable and when extracted, schemas can be found at drive:\Program Files\Microsoft BizTalk Server 2010\XSD_Schema\EDI. See more)

But it can vary and totally depends upon the requirement. See more.

And from the multiple data, specific data is to be mapped to a particular node.

In this article, BillTo and ShipTo nodes are used as an example to which data is to be mapped from repeating data (N1Loop).

                                                             Figure 1 : N1Loop1 properties

See this forum question.

Input file

ST*850*0001~
BEG*00*DS*45000007**20131002~
CUR*BY*USD~
REF*KK*STANDARD~
REF*BAI*8000~
REF*AAT*80206234~
REF*BLT*INVOICE~
REF*VR*1~
PER*BD*Collin Wag*TE*610-386-1189*FX*610-728-2210*EM*collin_wag@someemail.com~
N9*ZZ**REFERENCE NOTES~
N1*BT*Demo International*91*1100~
N2*WAN MIN-SV~
N3*PO Box 158~
N4*Secaus*NJ*07096*US~
PER*PR**TE*1110001111***EM*mahesht@ivisionsoftware.com~
N1*ST*BMS MEDEREX*91*00000~
N2*WAN MIN-SV~
N3*700  RD~
N4*RED CITY*CA*940632477*US~
PER*SH**TE*1110001111***EM*maheshstiwari@gmail.com~
N1*VN*Demo BIOSCIENCES*91*6868~
REF*PO*0043331289~
PO1*00001*2*PK*175.95*DI*VC*28-9165-37*CB*95056-246***PL*000040~
PO1*00001*2*PK*175.95*DI*VC*28-9165-37*CB*95056-246***PL*000040~
PID*F**ZZ*C*HITRAP CAPTO DEAE 1ML PK5 HITRAP CAPTO D~
PO4*1*1*PK~
REF*AAS*8013170709~
REF*BV*00004~
REF*PRT*2~
REF*LT*N~
DTM*002*20130828~
CTT*1~
SE*33*0001~

Mapping N1 loop to BillTo


                                                           Figure 2 : Mapping of N1 loop to BillTo

Below are the steps to map values from N1Loop to BillTo Node (non repeating):

Step 1: Drag a link from N1 Loop1 and connect it to BillTo Node.
Step 2: Drop a Equal functoid on map grid.
Step 3: Link N101 node (it holds the Party identifier value, BT) to Equal Functoid, this will be the first input.
Step 4: Double click the  Equal Functoid and set the value of the second input parameter as BT.


Figure 3:Input parameters to Equal functoid(BillTo)

Step 5: Link the output of Equal functoid to BillTo Node. Thus if value of N101 matches then the output of this functoid will be true and BillTo Node will be created.
Step 6: Now link the others as shown in figure 2.

Mapping N1 loop to ShipTo




                                                           Figure 4 : Mapping of N1 loop to ShipTo

Below are the steps to map values from N1Loop to ShipTo Node (non repeating):

Step 1: Drag a link from N1 Loop1 and connect it to ShipTo Node.
Step 2: Drop a Equal functoid on map grid.
Step 3: Link N101 node (it holds the Party identifier value, ST) to Equal Functoid, this will be the first input.
Step 4: Double click the  Equal Functoid and set the value of the second input parameter as ST.

Figure 5:Input parameters to Equal functoid(ShipTo)

Step 5: Link the output of Equal functoid to ShipTo Node. Thus if value of N101 matches then the output of this functoid will be true and ShipTo Node will be created.
Step 6: Now link the others as shown in figure 4.

XSLT code section of N1Loop


<xsl:for-each select="s0:N1Loop1">
  <xsl:for-each select="s0:N2">
    <xsl:variable name="var:v2" select="userCSharp:LogicalEq(string(../s0:N1/N101/text()) , "ST=""")" />
    <xsl:if test="$var:v2">
      <ShipTo>
        <xsl:if test="../s0:N1/N104">
          <ID>
            <xsl:value-of select="../s0:N1/N104/text()" />
          </ID>
        </xsl:if>
        <xsl:if test="../s0:N1/N102">
          <Name>
            <xsl:value-of select="../s0:N1/N102/text()" />
          </Name>
        </xsl:if>
        <AddressLine1>
          <xsl:value-of select="N201/text()" />
        </AddressLine1>
        <AddressLine2>
          <xsl:value-of select="../s0:N3/N301/text()" />
        </AddressLine2>
        <xsl:if test="../s0:N4/N401">
          <City>
            <xsl:value-of select="../s0:N4/N401/text()" />
          </City>
        </xsl:if>
        <xsl:if test="../s0:N4/N402">
          <State>
            <xsl:value-of select="../s0:N4/N402/text()" />
          </State>
        </xsl:if>
        <xsl:if test="../s0:N4/N403">
          <PostalCode>
            <xsl:value-of select="../s0:N4/N403/text()" />
          </PostalCode>
        </xsl:if>
        <xsl:if test="../s0:N4/N404">
          <Country>
            <xsl:value-of select="../s0:N4/N404/text()" />
          </Country>
        </xsl:if>
        <xsl:if test="../s0:PER_2/PER04">
          <TelephoneNumber>
            <xsl:value-of select="../s0:PER_2/PER04/text()" />
          </TelephoneNumber>
        </xsl:if>
        <xsl:if test="../s0:PER_2/PER08">
          <EmailAddress>
            <xsl:value-of select="../s0:PER_2/PER08/text()" />
          </EmailAddress>
        </xsl:if>
        <xsl:if test="..">
          <xsl:value-of select="../text()" />
        </xsl:if>
      </ShipTo>
    </xsl:if>
  </xsl:for-each>
</xsl:for-each>
<xsl:for-each select="s0:N1Loop1">
  <xsl:for-each select="s0:N2">
    <xsl:variable name="var:v3" select="string(../s0:N1/N101/text())" />
    <xsl:variable name="var:v4" select="userCSharp:LogicalEq($var:v3 , "BT=""")" />
    <xsl:if test="$var:v4">
      <BillTo>
        <xsl:if test="../s0:N1/N103">
          <ID>
            <xsl:value-of select="../s0:N1/N103/text()" />
          </ID>
        </xsl:if>
        <xsl:if test="../s0:N1/N102">
          <Name>
            <xsl:value-of select="../s0:N1/N102/text()" />
          </Name>
        </xsl:if>
        <AddressLine1>
          <xsl:value-of select="N201/text()" />
        </AddressLine1>
        <AddressLine2>
          <xsl:value-of select="../s0:N3/N301/text()" />
        </AddressLine2>
        <xsl:if test="../s0:N4/N401">
          <City>
            <xsl:value-of select="../s0:N4/N401/text()" />
          </City>
        </xsl:if>
        <xsl:if test="../s0:N4/N402">
          <State>
            <xsl:value-of select="../s0:N4/N402/text()" />
          </State>
        </xsl:if>
        <xsl:if test="../s0:N4/N403">
          <PostalCode>
            <xsl:value-of select="../s0:N4/N403/text()" />
          </PostalCode>
        </xsl:if>
        <xsl:if test="../s0:N4/N404">
          <Country>
            <xsl:value-of select="../s0:N4/N404/text()" />
          </Country>
        </xsl:if>
        <xsl:if test="../s0:PER_2/PER04">
          <TelephoneNumber>
            <xsl:value-of select="../s0:PER_2/PER04/text()" />
          </TelephoneNumber>
        </xsl:if>
        <xsl:if test="../s0:PER_2/PER08">
          <EmailAddress>
            <xsl:value-of select="../s0:PER_2/PER08/text()" />
          </EmailAddress>
        </xsl:if>
        <xsl:if test="..">
          <xsl:value-of select="../text()" />
        </xsl:if>
      </BillTo>
    </xsl:if>
  </xsl:for-each>
</xsl:for-each>

Output


<Header>
  <OrderId>45000007</OrderId>
  <OrderDate>2013-10-02</OrderDate>
  <Currency>USD</Currency>
  <ShipTo>
    <ID>00000</ID>
    <Name>BMS MEDEREX</Name>
    <AddressLine1>WAN MIN-SV</AddressLine1>
    <AddressLine2>700 RD</AddressLine2>
    <City>RED CITY</City>
    <State>CA</State>
    <PostalCode>940632477</PostalCode>
    <Country>US</Country>
    <TelephoneNumber>1110001111</TelephoneNumber>
    <EmailAddress>maheshstiwari@gmail.com</EmailAddress>
  </ShipTo>
  <BillTo>
    <ID>91</ID>
    <Name>Demo International</Name>
    <AddressLine1>WAN MIN-SV</AddressLine1>
    <AddressLine2>PO Box 158</AddressLine2>
    <City>Secaus</City>
    <State>NJ</State>
    <PostalCode>07096</PostalCode>
    <Country>US</Country>
    <TelephoneNumber>1110001111</TelephoneNumber>
    <EmailAddress>mahesht@ivisionsoftware.com</EmailAddress>
  </BillTo>
  <HeaderComment>This is Header Comment</HeaderComment>
</Header>
<Details>
  <Item>
    <ItemId>28-9165-37</ItemId>
    <ItemDescription>C</ItemDescription>
    <Quantity>2</Quantity>
    <UnitPrice>175.95</UnitPrice>
    <LineNumber>00001</LineNumber>
    <UOM>PK</UOM>
    <RequestedDeliveryDate>2013-10-02</RequestedDeliveryDate>
    <LineComment>This is line comment</LineComment>
  </Item>
</Details>


Author

Maheshkumar S Tiwari
iVision Software Pvt Ltd|User Page
http://tech-findings.blogspot.com/

See Also

Read suggested related topics:

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.

This article participates in the TechNet Guru for October competition.
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Maheshkumar S Tiwari edited Revision 5. Comment: Added Input file

  • Maheshkumar S Tiwari edited Revision 14. Comment: Added tags

  • Thanks Mahesh for sharing knowledge. I have been looking for this specific piece since a long. Good work.

  • HI Mahesh,

    I have done this with logical equal and looping functoid and it worked for me :)

    Thanks

    Abhishek

  • HI Mahesh,

    I have done this with logical equal and looping functoid and it worked for me :)

    Thanks

    Abhishek

  • Congratulations on the medal win! blogs.technet.com/.../technet-guru-awards-october-2013.aspx

Page 1 of 1 (6 items)