Check Shipment Date on Sales Order diff Unit Price table Sales Price

Hi Everybody,

I write procedure check Price on Sales Order and Sales Price (Id table : 7002) but it not work. I’m call procedure when click Shipment posting. (Page Warehouse Shipment)

Please help me fix code. Thanks so much.

WhseShipLine.SETFILTER(WhseShipLine."Source Document",'%1',WhseShipLine."Source Document"::"Sales Order");
SalesLine.SETFILTER("Document Type",'%1',SalesLine."Document Type"::Order);
SalesLine.SETRANGE(SalesLine."Document No.",WhseShipLine."Source No.");
WhseShipLine.SETRANGE("No.","No.");
IF "Shipment Method Code"=SalesPrice."Shipment Method Code" THEN BEGIN
SalesLine.SETFILTER(Type,'%1',SalesLine.Type::Item);
SalesLine.SETRANGE("Document No.",WhseShipLine."Source No.");
SalesLine.SETRANGE(SalesLine."No.",SalesPrice."Item No.");
SalesLine.SETRANGE(SalesLine."Sell-to Customer No.",SalesPrice."Sales Code");
SalesPrice.SETRANGE("Shipment Method Code","Shipment Method Code");
SalesLine.SETFILTER("Shipment Date",'%1 %2',SalesPrice."Starting Date",SalesPrice."Ending Date");
IF SalesPrice.FINDSET THEN REPEAT
    IF SalesPrice.ISEMPTY THEN
        ERROR('Sales Price not Shipment Date');
 UNTIL SalesPrice.NEXT=0;
  END;

Info on table Sales Price :

  • Item No; Sales Code (Customer No); Starting Date, Ending Date, Shipment Method Code and Unit Price

Sales Header : Shipment Method Code, Sell-to Customer No

Sales Line : Sell-to Customer No, No. (Item No), Shipment Date

Hi Dinhson,

Let me start by asking you the same question, you should ask whenever you get any NAV assignment!

What is the purpose of this code? And what is the code supposed to do? What does it do?

Hi Erik.

I’m check compare Unit Price by Shipment Date on Sales Order at Warehouse Shipment with Sales Price corresponding Customer and Shipment Method Code.

Hi Erik

I’m have edit code but code can’t check all line on table Sales Price.

Please fix help me. Thanks so much.

  SalesHeaderRec.SETRANGE("No.",SalesLine."Document No.");
  SalesHeaderRec.SETRANGE("Shipment Method Code",SalesPrice."Shipment Method Code");
  WhseShipLine.SETFILTER(WhseShipLine."Source Document",'%1',WhseShipLine."Source Document"::"Sales Order");
  SalesLine.SETFILTER("Document Type",'%1',SalesLine."Document Type"::Order);
  SalesLine.SETRANGE(SalesLine."Line No.",WhseShipLine."Line No.");
  SalesLine.SETRANGE(SalesLine."No.",WhseShipLine."Item No.");
  SalesLine.SETRANGE("Document No.",WhseShipLine."Source No.");
  IF SalesLine.FINDSET THEN
    SalesPrice.RESET;
    SalesPrice.SETRANGE(SalesPrice."Item No.",SalesLine."No.");
    SalesPrice.SETRANGE(SalesPrice."Sales Code",SalesLine."Sell-to Customer No.");
    REPEAT
    IF (SalesPrice."Ending Date" <> 0D) THEN
    IF SalesPrice.FINDFIRST THEN BEGIN
		IF  (SalesLine."Shipment Date" > SalesPrice."Starting Date") AND(SalesLine."Shipment Date" > SalesPrice."Ending Date") THEN
          ERROR('Sales Price not Shipment Date');
		IF  (SalesLine."Shipment Date" < SalesPrice."Starting Date") AND(SalesLine."Shipment Date" > SalesPrice."Ending Date") THEN
          ERROR('Sales Price not Shipment Date');
    END;
    UNTIL SalesPrice.NEXT=0;

Dear Dinhson,

I’m sorry to say it, but have you ever written NAV code before? Either you were drunk, when you wrote it, or you have never gotten any NAV development training. I guess the later, but hope the first.

Why filter on something you never use? Like SalesHeaderRec and WhseShipLine? And what’s up with the SETFILTER on Option fields, why not SETRANGE here. And the “SalesLine.SETRANGE(SalesLine.”'s?

Then we are down at where you have a SalesLine.FINDSET, but a SalesPrice.NEXT=0! You say you wanna check the sales price, but you only look at the first.

There are many books and documentation about NAV C/Side development. As well as many video’s. I really can suggest you to follow the webinar/YouTube course from NavSkils. You can also find the older episodes here on DUG, and sign up from NavSkills for the remaining webinars.

[View:~/nav/m/developer-documentation-rtc/477419:320:50]

Thanks you Erik with sincere advice.

I checked and removed the mistake. And its work

  SalesLine.SETFILTER("Document Type",'%1',SalesLine."Document Type"::Order);
  SalesLine.SETRANGE("Document No.",WhseShipLine."Source No.");
  IF SalesLine.FINDSET THEN
    SalesPrice.RESET;
    SalesPrice.SETRANGE(SalesPrice."Item No.",SalesLine."No.");
    SalesPrice.SETRANGE(SalesPrice."Sales Code",SalesLine."Customer Price Group");
    SalesPrice.SETFILTER(SalesPrice."Sales Type",'%1',SalesPrice."Sales Type"::"Customer Price Group");
      IF SalesPrice.FINDFIRST THEN BEGIN
        SalesPriceload.COPYFILTERS(SalesPrice);
        SalesPriceload.FINDFIRST;
      REPEAT
      IF (SalesPriceload.NEXT = 0) THEN BEGIN
      CLEAR(SalesPriceload);
      IF  (SalesPrice."Ending Date" <> 0D) THEN BEGIN
      IF (SalesLine."Shipment Date" > SalesPrice."Ending Date") THEN
          ERROR('Sales price of Item no %1 on Order :  %2 expired.',SalesPrice."Item No.",SalesLine."Document No.");
       END;
      END;
     UNTIL SalesPrice.NEXT=0;
    END;

That’s very good. BUT if you think that the above code works, then you should really test it 10 more times, with different test data. Because the code is still filled with problems and bad practices.

Thanks you Erik. You said exactly

It only works with the last line on table Sales Price. If on table has 2 condition, it will not execute.

I can’t break condition at here.

For example : SalesPrice.“Shipment Date” = 06/07/2018 then code not work.

Starting Date Ending Date
6/1/2018 6/6/2018
6/10/2018 6/12/2018