Please help. We had some nice smart automation that looked up reference numbers on a purchase invoice line description and automatically finds one or more sales shipment lines that correspond with that reference. The item charges are then automatically assigned. It was a huge productivity boost that is somehow not working after being upgraded to 15.2. There are no notes about this during the upgrade.
We still have a cloud 15.1 test environment in which our extension is being tested and works perfectly.
If there is a new best practice on how this should be done we cannot find any documentation on this?
The code in question is shown below.
procedure GetSalesShipmentByBookingReference(var PurchLine: Record "Purchase Line"; Reference: Text[100]): Boolean
var
ICAssignment: Record "Item Charge Assignment (Purch)" temporary;
ShipHeader: Record "Sales Shipment Header";
ShipLine: Record "Sales Shipment Line";
ICAssignmentCU: CodeUnit "Item Charge Assgnt. (Purch.)";
ShipmentCU: Codeunit "TFB Sales Shipment CU";
LineNo: Integer;
ChargesAssigned: Boolean;
begin
//Check if freight allocation already exists
Clear(ICAssignment);
LineNo := 10000;
ICAssignment.SetRange("Document No.", PurchLine."Document No.");
ICAssignment.SetRange("Document Type", PurchLine."Document Type"::Invoice);
ICAssignment.SetRange("Document Line No.", PurchLine."Line No.");
If ICAssignment.FindSet() then
If Dialog.Confirm('Assignment lines already exist - Remove them and continue?') then
ICAssignment.DeleteAll(false)
else
exit;
ShipHeader.SetRange("TFB 3PL Booking No.", Reference);
If ShipHeader.FindSet(false, false) then
repeat
//Retrieve Lines
Clear(ShipLine);
ShipLine.SetRange("Document No.", ShipHeader."No.");
ShipLine.SetRange(Type, ShipLine.Type::Item);
ShipLine.SetRange("Drop Shipment", false);
ShipLine.SetFilter(Quantity, '>0');
If ShipLine.FindSet(False, false) then
repeat
If ShipmentCU.GetItemChargesForSalesShipment(ShipHeader."No.", ShipLine."Line No.", 'S-FREIGHT') > 0 then
If not Dialog.Confirm('Charges already exist for shipment lines - Continue?') then
exit(false);
CLEAR(ICAssignmentCU);
ICAssignment."Document No." := PurchLine."Document No.";
ICAssignment."Document Type" := PurchLine."Document Type"::Invoice;
ICAssignment."Document Line No." := PurchLine."Line No.";
ICAssignment."Item Charge No." := PurchLine."No.";
ICAssignment."Item No." := ShipLine."No.";
ICAssignment."Line No." := LineNo;
ICAssignment.Description := ShipLine.Description;
ICAssignment."Applies-to Doc. No." := ShipHeader."No.";
ICAssignment."Applies-to Doc. Line No." := ShipLine."Line No.";
ICAssignment."Applies-to Doc. Type" := ICAssignment."Applies-to Doc. Type"::"Sales Shipment";
//Message removed and instead lightening performed if assignment is made
//Message(StrSubstNo('Inserting Shipment %1, %2, %3 on %4', ShipLine."Document No.", ShipLine."Line No.", ShipLine."No.", ShipHeader."Posting Date"));
LineNo := LineNo 10000;
ChargesAssigned := true;
ICAssignmentCU.CreateSalesShptChargeAssgnt(ShipLine, ICAssignment);
until ShipLine.Next() < 1;
until ShipHeader.Next() < 1;
If ChargesAssigned = true then begin
ICAssignmentCU.AssignItemCharges(PurchLine, PurchLine.Quantity, PurchLine.Amount, ICAssignmentCU.AssignByWeightMenuText());
PurchLine.Description := 'Sales Freight for ' Reference StrSubstNo(' for %1 on %2', ShipHeader."Ship-to Name", ShipHeader."Posting Date");
PurchLine.CalcFields("Qty. to Assign");
Exit(true);
end;
end;

Report
All responses (
Answers (