XMLport Repeating Data Example

Microsoft Dynamics Nav 2009

In a business document, you typically do not state the same information more than once. In a relational database, however, certain information must be repeated in various tables for data linking purposes.

Example

In the following XML sales order document, the <Items> node has the attribute Type="Order".

<?xml version="1.0" ?>
  <SalesOrder>
    <OrderHeader OrderDate="17-01-04">
      <SellTo CountryRegion="GB">
        <Name>The Cannon Group PLC</Name>
        <Address>192 Market Square</Address>
        <City>Birmingham</City>
        <Zip>B27 4KT</Zip>
      </SellTo>
      <BillTo CountryRegion="GB">
        <Name>The Cannon Group PLC</Name>
        <Address>192 Market Square</Address>
        <City>Birmingham</City>
        <Zip>B27 4KT</Zip>
        <PaymentTerms>14days</PaymentTerms>
      </BillTo>
    </OrderHeader>
    <Items Type="Order">
      <Item PartNum="LS-75">
        <ProductName>Loudspeaker, Cherry, 75W</ProductName>
          <Quantity>10</Quantity>
          <UnitPrice>79</UnitPrice>
          <ShipDate>12-10-04</ShipDate>
          <ShipTime>09:50</ShipTime>
          <Comment>Confirm that the amount of power is 75W</Comment>
      </Item>
      <Item PartNum="1908-8">
        <ProductName>LONDON Swivel Chair, blue</ProductName>
          <Quantity>12</Quantity>
          <UnitPrice>190,926</UnitPrice>
          <ShipDate>12-10-04</ShipDate>
          <ShipTime>09:50</ShipTime>
      </Item>
    </Items>
  </SalesOrder>

For this example, the Type="Order" information must be written to the Document Type field of the relevant table, the XML Sales Lines table. To cache the "Order" value, you would declare the Type attribute as a Text source type.

Node name Node type Source type Data source

Type

Attribute

Text

Type

To assign the Type value to each record in the XML Items - Import table, you could write the following code in the Import::OnAfterInitRecord trigger for the <Item> node: L.Document Type := Type;

See Also

Community Additions

ADD
Show: