Options

report 499: archive before deleting

kanikakanika Member Posts: 247
Hello everybody!!

I need to change the report 499 for to archive purchase orders before deleting them (cause the invoice is posted from invoices and not from orders, and so is not archived by default)

in OnAfterGetRecord () I added these lines:

PurchHeader.SETRANGE ("Document Type", "Document Type");
PurchHeader.SETRANGE ("No.", "No.");
ArchiveManagement.ArchivePurchDocument (PurchHeader);

ArchiveManagement is the codeunit used in Orders/Functions/Archive Document

but does not archive, only does delete :(

Answers

  • Options
    ebsoftebsoft Member Posts: 81
    kanika wrote:
    Hello everybody!!

    I need to change the report 499 for to archive purchase orders before deleting them (cause the invoice is posted from invoices and not from orders, and so is not archived by default)

    in OnAfterGetRecord () I added these lines:

    PurchHeader.SETRANGE ("Document Type", "Document Type");
    PurchHeader.SETRANGE ("No.", "No.");
    ArchiveManagement.ArchivePurchDocument (PurchHeader);

    ArchiveManagement is the codeunit used in Orders/Functions/Archive Document

    but does not archive, only does delete :(

    Kanika,
    just add a:
    PurchHeader.FINDSET;
    
    before calling ArchivePurchDocument procedure.
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
  • Options
    kanikakanika Member Posts: 247
    so

    PurchHeader.SETRANGE ("Document Type", "Document Type");
    PurchHeader.SETRANGE ("No.", "No.");
    PurchHeader.FINDSET;
    ArchiveManagement.ArchivePurchDocument (PurchHeader);

    but this still does not work :(
  • Options
    ebsoftebsoft Member Posts: 81
    kanika wrote:
    but this still does not work :(

    Kanika,
    where did you put this code?
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
  • Options
    kanikakanika Member Posts: 247
    Purchase Header - OnAfterGetRecord()

    Window.UPDATE(1,"No.");
    AllLinesDeleted := TRUE;
    DocDim.RESET;
    DocDim.SETRANGE("Document Type","Document Type");
    DocDim.SETRANGE("Document No.","No.");
    ItemChargeAssgntPurch.RESET;
    ItemChargeAssgntPurch.SETRANGE("Document Type","Document Type");
    ItemChargeAssgntPurch.SETRANGE("Document No.","No.");
    PurchLine.RESET;
    PurchLine.SETRANGE("Document Type","Document Type");
    PurchLine.SETRANGE("Document No.","No.");
    PurchLine.SETFILTER("Quantity Invoiced",'<>0');
    IF PurchLine.FIND('-') THEN BEGIN
    PurchLine.SETRANGE("Quantity Invoiced");
    PurchLine.SETFILTER("Outstanding Quantity",'<>0');
    IF NOT PurchLine.FIND('-') THEN BEGIN
    PurchLine.SETRANGE("Outstanding Quantity");
    PurchLine.SETFILTER("Qty. Rcd. Not Invoiced",'<>0');
    IF NOT PurchLine.FIND('-') THEN BEGIN
    PurchLine.LOCKTABLE;
    IF NOT PurchLine.FIND('-') THEN BEGIN
    PurchLine.SETRANGE("Qty. Rcd. Not Invoiced");
    DocDim.SETRANGE("Table ID",DATABASE::"Purchase Line");
    IF PurchLine.FIND('-') THEN
    REPEAT
    PurchLine.CALCFIELDS("Qty. Assigned");
    IF ((PurchLine."Qty. Assigned" = PurchLine."Quantity Invoiced") AND
    (PurchLine."Qty. Assigned" <> 0)) OR
    (PurchLine.Type <> PurchLine.Type::"Charge (Item)")
    THEN BEGIN
    DocDim.SETRANGE("Line No.",PurchLine."Line No.");
    PurchHeader.SETRANGE("Document Type","Document Type");
    PurchHeader.SETRANGE("No.","No.");
    PurchHeader.FINDSET;
    ArchiveManagement.ArchivePurchDocument(PurchHeader);

    DocDim.DELETEALL;
    IF PurchLine.Type = PurchLine.Type::"Charge (Item)" THEN BEGIN
    ItemChargeAssgntPurch.SETRANGE("Document Line No.",PurchLine."Line No.");
    ItemChargeAssgntPurch.DELETEALL;
    END;
    IF PurchLine.HASLINKS THEN
    PurchLine.DELETELINKS;

    PurchLine.DELETE;
    END ELSE
    AllLinesDeleted := FALSE;
    UNTIL PurchLine.NEXT = 0;

    IF AllLinesDeleted THEN BEGIN
    PurchPost.DeleteHeader(
    "Purchase Header",PurchRcptHeader,PurchInvHeader,PurchCrMemoHeader,
    ReturnShptHeader,PrepmtPurchInvHeader,PrepmtPurchCrMemoHeader);

    ReservePurchLine.DeleteInvoiceSpecFromHeader("Purchase Header");

    PurchCommentLine.SETRANGE("Document Type","Document Type");
    PurchCommentLine.SETRANGE("No.","No.");
    PurchCommentLine.DELETEALL;

    DocDim.SETRANGE("Table ID",DATABASE::"Purchase Header");
    DocDim.SETRANGE("Line No.",0);
    DocDim.DELETEALL;

    WhseRequest.SETRANGE("Source Type",DATABASE::"Purchase Line");
    WhseRequest.SETRANGE("Source Subtype","Document Type");
    WhseRequest.SETRANGE("Source No.","No.");
    WhseRequest.DELETEALL(TRUE);

    IF HASLINKS THEN
    DELETELINKS;

    DELETE;
    END;
    COMMIT;
    END;
    END;
    END;
    END;
  • Options
    ebsoftebsoft Member Posts: 81
    You are inside a loop for Purchase Line...

    Try to put the code after
    Window.UPDATE(1,"No.");
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
  • Options
    kanikakanika Member Posts: 247
    neither

    Could it be the codeunit?


    if there were an ARCHIVEALL like exists an DELETEALL.............................
  • Options
    ebsoftebsoft Member Posts: 81
    kanika wrote:
    neither

    Could it be the codeunit?

    Have you modified the codeunit too?
    Try to call directly:
    ArchiveManagement.StorePurchDocument(PurchHeader,FALSE);
    

    instead of
    ArchiveManagement.ArchivePurchDocument(PurchHeader);
    
    kanika wrote:
    if there were an ARCHIVEALL like exists an DELETEALL.............................

    Lol... this has to be written in a book! :D
    DELETEALL is a Nav internal function.
    ARCHIVEALL does not exist!
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
  • Options
    kanikakanika Member Posts: 247
    ok! I just discovered the error

    was in the codeunit

    had effectively changed to avoid having to confirm each record


    now work perfectly


    really thank you very much
  • Options
    ebsoftebsoft Member Posts: 81
    kanika wrote:
    ok! I just discovered the error

    was in the codeunit

    had effectively changed to avoid having to confirm each record


    now work perfectly


    really thank you very much

    Just restore the confirm (if you need it per each order).
    It was asked for each line because you previously put the code into the line loop!

    You're welcome.
    Regards,
    Federico

    MBS Specialist since NAV 2.0
    My experiences on Linkedin
Sign In or Register to comment.