Open Forum

Expand all | Collapse all

Updating Sales Lines On Released Orders with Codeunits

  • 1.  Updating Sales Lines On Released Orders with Codeunits

    TOP CONTRIBUTOR
    Posted Sep 20, 2020 05:02 PM
    Hi All

    Writing an extension where I need to update an item on several sales lines, but some of the salesorders are released

    How would I check if the sales order is released, reopen it, and re-release after modification?


    Here's the main part of my proc:

            SalesLine.SETRANGE("Document Type",SalesLine."Document Type"::Order);          
           SalesLine.SETRANGE(Type, SalesLine.Type::Item);
           SalesLine.SetFilter("No.", '= %1', SourceItemNo);

            IF SalesLine.FINDSET(TRUETHEN
               REPEAT    
    // Get Sales Header
                    SalesHeader.Get(SalesLine."Document Type", SalesLine."Document No.");
                   // Change item no and validate
    SalesLine
    .Validate("No.", NewItemNo);    
                   SalesLine.MODIFY(TRUE);
                UNTIL SalesLine.NEXT = 0;
    Thanks

    Mark

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------
    Academy - Online Interactive Learning from Experts


  • 2.  RE: Updating Sales Lines On Released Orders with Codeunits

    Posted Sep 21, 2020 06:56 AM
    Hi Mark,

    This should do the trick. Doesn't include any error handling though.

      IF SalesLine.FINDSET(TRUETHEN
                REPEAT     
                    // Get Sales Header
                    SalesHeader.Get(SalesLine."Document Type", SalesLine."Document No.");

                    //>>HN
                    if SalesHeader.Status = SalesHeader.Status::Released then begin
                        SalesHeaderReleased := True;
                        ReleaseSalesDocument.Reopen(SalesHeader);
                    end;
                    //<<HN

                    // Change item no and validate
                    SalesLine.Validate("No.", NewItemNo);     
                    SalesLine.MODIFY(TRUE);

                    //>>HN
                    if SalesHeaderReleased then
                        ReleaseSalesDocument.ReleaseSalesHeader(SalesHeader,false);
                    //<<HN

                UNTIL SalesLine.NEXT = 0;


    ------------------------------
    Hasse Nielsen
    ENAVATE
    Englewood
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 3.  RE: Updating Sales Lines On Released Orders with Codeunits

    TOP CONTRIBUTOR
    Posted Sep 24, 2020 09:45 AM

    Thanks Hasse!

     

     

     

    Mark Anderson | Director of ERP Systems

     

    Mobile 312.576.4332 | Direct 847.448.4202

     

     




    Academy - Online Interactive Learning from Experts


If you've found this thread useful, dive deeper into User Group community content by role