Sales Shipment Header

RikarddoRikarddo Member Posts: 80
Hi,

I created a table with all possible combinations, based on historic sales, of origin and destination of Post Codes and it's distance in Kms . My point here is to fill up a field in Sales Shipment Line with distance based on the other table.

For example a Shipment of Customer X From A to B in a total of Z Kms.

I created a ProcessingOnly Report to insert in Sales Shipment Line the kms.
My table has this fields :
Code, Customer, PostCode Origin, Post Code Destination, Distance
Where Customer, PostCode Origin, Post Code Destination is a key.

Here is what i tried to do:
Sales Shipment Header - OnAfterGetRecord()

Location.RESET;
Location.SETRANGE(Code,"Sales Shipment Header"."Location Code");
IF Location.FIND('-') THEN 
   loc:=Location."Post Code";
  

   DistanciaEntrega.RESET;
   DistanciaEntrega.SETRANGE(DistanciaEntrega."No.", "Sales Shipment Header"."Sell-to Customer No.");
   DistanciaEntrega.SETRANGE("Cod. Origem",loc);
   DistanciaEntrega.SETRANGE("Cod. Entrega","Sales Shipment Header"."Ship-to Post Code");
   IF DistanciaEntrega.FIND('-') THEN
     SalesShipmentLine.RESET;
     SalesShipmentLine.SETRANGE("Document No.","Sales Shipment Header"."No.");
     SalesShipmentLine.SETRANGE("Sell-to Customer No.","Sales Shipment Header"."Sell-to Customer No.");
     SalesShipmentLine.SETRANGE(Type,SalesShipmentLine.Type::Item);
     SalesShipmentLine.SETFILTER("No.",'<>%1','');
     SalesShipmentLine.SETRANGE("Item Container",FALSE);
   
     IF SalesShipmentLine.FINDSET THEN REPEAT
      SalesShipmentLine.Distance:=DistanciaEntrega.Distance;
      SalesShipmentLine.MODIFY;
     UNTIL SalesShipmentLine.NEXT=0;

But i Can't get the code from my table with sales shipment header.
What am i doing wrong?

Comments

  • KarenhKarenh Member Posts: 209
    Sales Shipment Line is related to Sales Shipment Header on Document No. = No. You do not need to add the filter on the Sell-to Customer No.

    But, to the point of the issue, have you tried stepping through the code with the debugger? That would be my next move.

    One more suggestion. If you are going to edit a record, it is better to use
    FINDSET(TRUE, FALSE) so that it is locked. What you are doing works, but is not optimal.
  • RikarddoRikarddo Member Posts: 80
    edited 2017-11-26
    Karenh wrote: »
    Sales Shipment Line is related to Sales Shipment Header on Document No. = No. You do not need to add the filter on the Sell-to Customer No.

    It solved my problem. Thanks a lot!

    Just didn't understood the FINDSET(True,False) part.
  • latronamarranlatronamarran Member Posts: 24
    the first parameter of findset tells whether you are going to update the filtered table or not. If true than than second parameter tells whether you're going to update a field which is one of your filters of that table.
Sign In or Register to comment.