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
0
Answers
It's impossible to figure out more details without reviewing the code. Can you share it in this thread?
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
If you wish for us to help you, please share the contents of codeunit 50001
Thanks for your concern, I shall share the codeunit 50001 content as below. Sorry I failed to attached it.
Thanks in advance,
Fredrick.
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;
////
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.
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
May be some sequence would be wrong
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
I did run the debugger it stops at table 474 - Job queue log entry
Function - Get Error Message.
Thanks I tried to change change the code as of your suggestion but I keep getting the same error.
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.