Sales order Copy to another company

CeRBeRCeRBeR Member Posts: 3
edited 2014-03-07 in NAV Three Tier
Hi Every One,

I try a copy sales order A to B company on Nav 2013. It's perfectly working but when i delete a sales line record on A Company, i can't delete ReserveSalesLine.DeleteLine(rec) on B company.

How can i use this codeunit on B company

Thanks for help

Comments

  • ara3nara3n Member Posts: 9,256
    It's unclear what you are trying to do. You need to clarify your question and what you are trying to do.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • CeRBeRCeRBeR Member Posts: 3
    Hi @ara3n. Thank you for interesting.

    We have 2 company on our NAV 2013. A company for only sales and marketing(EVG) other company only for manufacturing(ANK). All sales order opening EVG company and we are copy this order to ANK company manually. After we are run planing on ANK company...
    I write a Codeunit for this situation and running smootly. But only delete processes does not work properly.

    My code below


    .
    .
    .
    .
    AnkSalesLine.SETRANGE("No.",Rec."No.");
    AnkSalesHeader.RESET();
    AnkSalesHeader.CHANGECOMPANY('ANK');
    AnkSalesHeader.SETRANGE("No.",Rec."Document No.");
    IF (AnkSalesHeader.FINDFIRST) AND (AnkSalesHeader.Status = AnkSalesHeader.Status::Open) THEN BEGIN
    IF AnkSalesLine.FINDFIRST THEN
    ERROR('blablabalba');
    CapableToPromise.RemoveReqLines(AnkSalesLine."Document No.",AnkSalesLine."Line No.",0,FALSE);
    ReserveSalesLine.DeleteLine(AnkSalesLine);
    AnkSalesLine.DELETE();
    END ELSE BEGIN
    ERROR(Text061);
    END;


    The red words not working ANK company with changecompany function. How can i run this 2 function on ANK company
  • ara3nara3n Member Posts: 9,256
    You need to create a new Codeunit for example called "Delete Sales Order" 50000.


    In OnRun (Sales Header record ) as parameter

    You Code .. to delete without the change company.
    AnkSalesHeader.SETRANGE("No.",Rec."Document No.");
    IF (AnkSalesHeader.FINDFIRST) AND (AnkSalesHeader.Status = AnkSalesHeader.Status::Open) THEN BEGIN
    IF AnkSalesLine.FINDFIRST THEN
    ERROR('blablabalba');
    CapableToPromise.RemoveReqLines(AnkSalesLine."Document No.",AnkSalesLine."Line No.",0,FALSE);
    ReserveSalesLine.DeleteLine(AnkSalesLine);
    AnkSalesLine.DELETE();
    



    You will then call this Codeunit from your process this way.
    STARTSESSION(SessionID,50000,'ANK',SalesHeader);

    your code will not work because t executes in current company. You are only changing company on salesheader, all other code is run in current company
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.