The Sales Header does not exist

NagaboonaNagaboona Member Posts: 33
Good day,

I have a job queue that would automatically generate invoices and receipts for your customers. Unfortunately it is now giving errors:

The Sales Header does not exist. Identification fields and values: Document Type='Invoice',No.='INV-00555459'

and no more invoices or receipts are being generated.

Could someone please assist on how to sort this out?

Thanks,

Nagab

Answers

  • PhoguePhogue Member Posts: 74
    You're trying to GET, MODIFY, or RENAME a Sales Header with Type = Invoice, and No. = INV-00555459.

    It's impossible to figure out more details without reviewing the code. Can you share it in this thread?
  • NagaboonaNagaboona Member Posts: 33
    Hi Phogue,

    Thanks a lot for your response.

    I have a job queue that automatically generate invoices and receipts for our customers. However, for some reasons it has stopped working with the mentioned error message as in the attachment.

    Regards,

    Nagab
  • NagaboonaNagaboona Member Posts: 33
    Please see attachment of the error
  • PhoguePhogue Member Posts: 74
    Hi Nagaboona,

    If you wish for us to help you, please share the contents of codeunit 50001

  • NagaboonaNagaboona Member Posts: 33
    Hello Phogue,

    Thanks for your concern, I shall share the codeunit 50001 content as below. Sorry I failed to attached it.

    Thanks in advance,

    Fredrick.
  • NagaboonaNagaboona Member Posts: 33
    Documentation()

    OnRun()

    GenerateInvoice();

    GenerateReceipt();

    DeleteSuccessJobQueueLogEntry();

    GenerateInvoice()

    rRec.RESET;
    rRec.COPYFILTERS(Rec);
    rRec.SETFILTER("Invoice Created?",FORMAT(FALSE));
    rRec.SETFILTER(rRec."Receipt Created?",FORMAT(FALSE));
    rRec.SETFILTER(rRec."Bill Status",'2');
    rRec.SETFILTER(rRec."Zone Code",'<>%1',0);
    rRec.SETRANGE(rRec.Status,rRec.Status::Permanent);
    IF rRec.FINDFIRST THEN
    BEGIN
    REPEAT
    //Navision customer
    Cust.SETRANGE("No.",rRec."Customer No.");
    IF Cust.FINDFIRST THEN
    BEGIN
    //Get the document number to be used to generate the Invoice
    SalesRecSetup.RESET;
    IF SalesRecSetup.GET(SalesRecSetup."Invoice Nos.") THEN
    BEGIN
    InvNo:=SalesRecSetup."Invoice Nos.";
    END;
    SalesH.RESET;
    SalesH.SETRANGE("Document Type",SalesH."Document Type"::Invoice);
    SalesH.SETRANGE("No. Series",InvNo);
    IF SalesH.FINDLAST THEN
    BEGIN
    DocumentNo:=INCSTR(SalesH."No.");
    END
    ELSE
    BEGIN
    DocumentNo:=NoSeriesMgt.GetNextNo(InvNo,0D,FALSE);
    END;

    //Insert Header
    SalesH.RESET;
    SalesH.INIT;
    SalesH."No.":=DocumentNo;
    SalesH.VALIDATE("No.");
    SalesH."No. Series":=InvNo;
    SalesH."Document Type":=SalesH."Document Type"::Invoice;
    SalesH."Control Number":=rRec."Bill Control Number";
    SalesH."Sell-to Customer No.":=rRec."Customer No.";
    SalesH.VALIDATE("Sell-to Customer No.");
    {SalesH."Shortcut Dimension 1 Code":=ActCode;
    SalesH.VALIDATE("Shortcut Dimension 1 Code");
    SalesH."Shortcut Dimension 2 Code":=BLcode;
    SalesH.VALIDATE("Shortcut Dimension 2 Code");}
    SalesH.INSERT;

    //Insert Lines
    BillItems.RESET;
    BillItems.SETRANGE("Bill ID",rRec.Bill_ID);
    IF BillItems.FINDFIRST THEN
    REPEAT
    IF BillItems.FINDLAST THEN LineNo:=LineNo+1000 ELSE LineNo:=1000;
    SalesL.RESET;
    SalesL.INIT;
    SalesL."Document Type":=SalesL."Document Type"::Invoice;
    SalesL."Document No.":=DocumentNo;
    SalesL."Line No.":=LineNo;
    SalesL.Type:=SalesL.Type::"G/L Account";
    SalesL."No.":=BillItems."GL Code";
    SalesL.VALIDATE("No.");
    SalesL.Description:=BillItems.Description;
    SalesL."Unit of Measure Code":='FEE';
    SalesL.Quantity:=1;
    SalesL.VALIDATE(Quantity);
    SalesL."Unit Price":=BillItems."Bill Item Amount";
    SalesL.VALIDATE("Unit Price");

    SalesL."Shortcut Dimension 1 Code":=BillItems."Activity Code";
    SalesL.VALIDATE("Shortcut Dimension 1 Code");
    SalesL."Shortcut Dimension 2 Code":=BillItems."Budget Line Code";
    SalesL.VALIDATE("Shortcut Dimension 2 Code");

    SalesH."Shortcut Dimension 1 Code":=BillItems."Activity Code";
    SalesH.VALIDATE("Shortcut Dimension 1 Code");
    SalesH."Shortcut Dimension 2 Code":=BillItems."Budget Line Code";
    SalesH.VALIDATE("Shortcut Dimension 2 Code");

    SalesL.INSERT;
    UNTIL BillItems.NEXT=0;

    rRec."Invoice No.":=DocumentNo;
    rRec."Invoice Created?":=TRUE;
    rRec.Select:=FALSE;
    rRec.MODIFY;

    //Update No. Series
    NoSeries.SETRANGE("Series Code",'INVOICE');
    IF NoSeries.FINDFIRST THEN
    BEGIN
    NoSeries."Last No. Used":=DocumentNo;
    NoSeries.MODIFY;
    END;
    ////

  • NagaboonaNagaboona Member Posts: 33
    Hello Phogue,

    I have attached the code in PDF since other formats are not supported and the code is too long.

    Please do not hesitate to ask me any thing that be required to get me out of this hook.

    Thanking you in advance,

    Fredrick.
  • PhoguePhogue Member Posts: 74
    If you run a debugger, when exactly (in the code) does the error appear?
  • lubostlubost Member Posts: 577
    Your code should looks like:
    rRec.RESET;
    rRec.COPYFILTERS(Rec);
    rRec.SETRANGE("Invoice Created?", FALSE);
    rRec.SETRANGE("Receipt Created?", FALSE);
    rRec.SETRANGE("Bill Status", '2');
    rRec.SETFILTER(rRec."Zone Code", '<>%1', 0);
    rRec.SETRANGE(Status, rRec.Status::Permanent);
    IF rRec.FINDSET THEN
    REPEAT
    SalesRecSetup.GET;
    SalesH.RESET;
    SalesH.INIT;
    SalesH."Document Type" := SalesH."Document Type"::Invoice;
    SalesH."No. Series" := SalesRecSetup."Invoice Nos.";
    SalesH.INSERT(TRUE);
    SalesH."Control Number" := rRec."Bill Control Number";
    SalesH.VALIDATE("Sell-to Customer No.", rRec."Customer No.");
    SalesH.MODIFY(TRUE);
    and then continue with lines
  • lubostlubost Member Posts: 577
    ... and hint: Do not use characters with potentially special meaning (?) in column names.
  • RockWithNAVRockWithNAV Member Posts: 989
    @Nagaboona - You need to debug it out and see where is the glitch , going through this lengthy code wont help.
    May be some sequence would be wrong
  • NagaboonaNagaboona Member Posts: 33
    Hello Phogue,

    I did run the debugger it stops at table 474 - Job queue log entry
    Function - Get Error Message.
  • NagaboonaNagaboona Member Posts: 33
    Hello Lubost,

    Thanks I tried to change change the code as of your suggestion but I keep getting the same error.
  • lubostlubost Member Posts: 577
    Continued with lines:
    LineNo := 10000;
    BillItems.RESET;
    BillItems.SETRANGE("Bill ID", rRec.Bill_ID);
    IF BillItems.FINDSET THEN
    REPEAT
    SalesL.RESET;
    SalesL.INIT;
    SalesL."Document Type":=SalesH."Document Type";
    SalesL."Document No.":=SalesH."No.";
    SalesL."Line No.":=LineNo;
    SalesL.Type:=SalesL.Type::"G/L Account";
    SalesL.VALIDATE("No.", BillItems."GL Code");
    SalesL.Description:=BillItems.Description;
    SalesL."Unit of Measure Code":='FEE';
    SalesL.VALIDATE(Quantity, 1);
    SalesL.VALIDATE("Unit Price". BillItems."Bill Item Amount");
    SalesL.VALIDATE("Shortcut Dimension 1 Code", BillItems."Activity Code");
    SalesL.VALIDATE("Shortcut Dimension 2 Code", BillItems."Budget Line Code");
    SalesH.VALIDATE("Shortcut Dimension 1 Code", BillItems."Activity Code");
    SalesH.VALIDATE("Shortcut Dimension 2 Code", BillItems."Budget Line Code");
    SalesH.VALIDATE("Shortcut Dimension 2 Code");
    SalesL.INSERT;
    UNTIL BillItems.NEXT=0;
    SalesH.MODIFY;
    rRec."Invoice No.":=SalesH."No.";
    rRec."Invoice Created?":=TRUE;
    rRec.Select:=FALSE;
    rRec.MODIFY;

    and without any touch to NoSeries table.

    Modifying header dimensions again and again with each line has no effect, because:
    - last value will be used
    - validation trigger in header changes all lines values.
Sign In or Register to comment.