XMLPort return all possible prices of customer

NoiK00NoiK00 Member Posts: 51
edited 2013-10-25 in NAV Three Tier
Hi all,

A few days i am pounding on a problem and i can't seem to find a fitting solution.
I have to produce a XML output which can give the possible prices and discounts.
In NAV there is more then one way to retrieve a discount("Customer", "All customers", "Customer disc. Groups" and there is the combination with "Item" and "Item disc. group").

The XML format i'm trying to produce is:
<products>
  <product id="" xmlns="urn:microsoft-dynamics-nav/api/product/getprice">
    <price />
    <itemdiscgroup />
    <custdiscgroup />
    <linediscounts>
      <linediscount min="">
        <discount />
        <start />
        <end />
      </linediscount>
    </linediscounts>
  </product>
</products>

How can i, based on table 7004, return the list with possible line discounts?

I've tried setting linediscount as a TEMPORARY table and filling it in the ONPREXMLITEM() trigger.
As an example:
linediscount - Export::OnPreXMLItem()
SLD.RESET;

//all customers x item
TempSalesLineDiscount.SETRANGE(TempSalesLineDiscount.Type, TempSalesLineDiscount.Type::Item);
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount.Code, Item."No.");
TempSalesLineDiscount.SETRANGE(TempSalesLineDiscount."Sales Type", TempSalesLineDiscount."Sales Type"::"All Customers");
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Starting Date", '%1|<=%2', 0D, TODAY);
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Ending Date", '%1|>=%2', 0D, TODAY);

TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Minimum Quantity", '<> 0');

CopySalesDiscToSalesDisc(TempSalesLineDiscount, SLD);

//specific customer x item
TempSalesLineDiscount.RESET;
TempSalesLineDiscount.SETRANGE(TempSalesLineDiscount.Type, TempSalesLineDiscount.Type::Item);
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount.Code, Item."No.");
TempSalesLineDiscount.SETRANGE(TempSalesLineDiscount."Sales Type", TempSalesLineDiscount."Sales Type"::Customer);
TempSalesLineDiscount.SETRANGE(TempSalesLineDiscount."Sales Code", Customer."No.");
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Starting Date", '%1|<=%2', 0D, TODAY);
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Ending Date", '%1|>=%2', 0D, TODAY);
TempSalesLineDiscount.SETFILTER(TempSalesLineDiscount."Minimum Quantity", '<> 0');

CopySalesDiscToSalesDisc(SLD, TempSalesLineDiscount);


CopySalesDiscToSalesDisc(VAR FromSalesLineDisc : Record "Sales Line Discount";VAR ToSalesLineDisc : TEMPORARY Record "Sales Line Discou
WITH ToSalesLineDisc DO BEGIN
  IF FromSalesLineDisc.FINDSET THEN
    REPEAT
      IF FromSalesLineDisc."Line Discount %" <> 0 THEN BEGIN
        ToSalesLineDisc.COPY(FromSalesLineDisc);
        ToSalesLineDisc.INSERT;
      END;
    UNTIL FromSalesLineDisc.NEXT = 0;
END;

But this gives me a duplicate record error.

Can you guys give me any leads in finding a solution for this?

Thanks in advance.
NoiK
Sign In or Register to comment.