web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

Code that automatically assigned charges worked in 15.1 and has stopped working in 15.2 of Business Central

(0) ShareShare
ReportReport
Posted on by 208

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;

  • RustyAustralis Profile Picture
    208 on at

    One comment.  There is no error reported. There is just simply no charge assignment line created in 15.2.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 664 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 446 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 282 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans