Hi all
Im' having a strange problem. I created a codeunit that automaticaly emails the sales invoice as soon as it's posted. When I add code to codeunit 82(Sales-Post + Print) (we need to email only if printed), it gives an error that the Sales Header does not exist. It prints report fine, but fails to created a report to email. However, if I put my code to generate email first, then it emails fine, but fails to print. here is my code:
SalesPost.RUN(SalesHeader);
GetReport(SalesHeader);
//Send Email
IF Invoice THEN
IF SalesHeader."Document Type" IN ["Document Type"::Order,"Document Type"::"Credit Memo"] THEN
CreateEmail.CreateInvoice(SalesHeader."Last Posting No.");
I use the standart Sales Invoice report (10074). I'm running navision 4 SP2.
Comments
Information from SalesHeader table after posting are transfered to Sales Invoice Header.
At least this is the standard W1 Sales Invoice Report (R206). Your report is not standard W1, but is a localized report.
So I think you should try this: And don't forget to use table 112 in "CreateInvoice" or 114 in "CreateCreditMemo".
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Still cannot make work.Thank you in advance
-check if the invoiceno has the correct value.
-does it give an error? If yes, which error.
-try to give the function an invoice you know exists and run it.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
1. The Invoiceno has the correct value
2. The error i'm getting is Sales Order #### does not exist. The order ## is the same order being posted
3. I try that, I pass already posted invoice. I'm getting error : Sales Order #### does not exist where he order ## is the same order being posted. for exmaple, I'm trying to post order No. 111. I supply function with Invoice No. 222 => I'm geting error regarding order 111.
if debugger is on, it does not fire the debugger.
](*,) ](*,)
I think it is just a message. In this case you will have to debug all to find where the message comes up. (or check in the textconstants of the objects if you find the message and then search the object for the textconstant. In this way you know where the message comes up and also why).
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
You maybe right. it could be a message because it does not trigger the debugger. I tried to debug it, but everytime it's working just fine when using F5 I will try to look in the objects.
After all code has been executed, put a CurrForm.UPDATE(FALSE);
and lets see if this helps.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I put it after execution of Post and print. Still the same problem.
First run the send email function with an invoice that already exists. Do this from a new object with no other code in it. Lets see if this works. (If not, the problem is in here).
If this works, try to post an order but WITHOUT running the email part and see if this works. (if not, the problem is in here)
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
2. Stripped the email function to just generate a report (no other code). It gives an error. If I check the direcotry where HTML should be save, the invoice is there. so it does create the invoice propertly.
If it is the first, it means that after the report has run, some code is executed that generates the error. In this case, you might try to comment the code that prints/emails and see what happens with the debugger. Probably the wrong code is somewhere in the trigger that calls the posting+printing codeunit (or IN that codeunit).
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No it does not. If I manually debug the debugger can stop at any place. mostly of the time on CurrReport.BREAK in CopyLoop. But reports is saving just fine(even using 100% standatrd report). I tired to create a smiple report based on table 112 to run it with my CU. It gives the same error. So, it for sure not a report problem.
Put the message and extra code I put in it.
Record the messages you have and in which order they appear.
With this we can see in which function/codeunit/object/... the problem arises.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
CLEAR(InvoiceAsEmail);
SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
InvoiceAsEmail.USEREQUESTFORM :=FALSE;
InvoiceAsEmail.SETTABLEVIEW(SalesInvoiceHeader.);
InvoiceAsEmail.SAVEASHTML('C:\Somedirectory');
MESSAGE('GENERATED');
It never gets to this message either, but the reports is saved.
Lets try this: Lets see if the message comes up.
If it comes up, try the debugger to find where it goes wrong.
If it doesn't come up, try the other code (with "SAVEASHTML") and use the debugger to find where it goes wrong.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Ok. Tried code above. no errors. Test it for a long time. Then I tried the following code:
SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
REPORT.SAVEASHTML(50200, 'C:\Somedirectory\file.html', FALSE,SalesInvoiceHeader);
This gave me the same error. The HTML file is still creating. What is going on? ](*,) ](*,) ](*,) ](*,) ](*,) ](*,)
In this case, you need to try to create the error on a Cronus-DB and send it to Microsoft to fix it.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!