Options

Automatic Emailing on Posting

deniliadenilia Member Posts: 23
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

  • Options
    andrejsmandrejsm Member Posts: 122
    Hi,
    Information from SalesHeader table after posting are transfered to Sales Invoice Header.
    Andrejs Muraskins
  • Options
    deniliadenilia Member Posts: 23
    But Reports prints fine with Salesheader. If I retrieve the invoice number before Getreport, I have the same issue.
  • Options
    jversusjjversusj Member Posts: 489
    edited 2006-07-24
    edit: nothing to see here :whistle: .
    kind of fell into this...
  • Options
    krikikriki Member, Moderator Posts: 9,090
    denilia wrote:
    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.
    Posting an invoice moves the invoice from table 36 to table 112. So when you post+print an invoice, the posting happens and then the report prints the invoice. But this invoice is the invoice in Table 112.
    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:
    SalesPost.RUN(SalesHeader);
    //Send Email
    IF Invoice THEN BEGIN
      CASE SalesHeader."Document Type" OF
        SalesHeader."Document Type"::Order, SalesHeader."Document Type"::Invoice:
          CreateEmail.CreateInvoice(SalesHeader."Last Posting No.");
        SalesHeader."Document Type"::"Credit Memo":
          CreateEmail.CreateCreditMemo(SalesHeader."Last Posting No.");
      END;
    END;
    
    And don't forget to use table 112 in "CreateInvoice" or 114 in "CreateCreditMemo".
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    Thank you for replies. i understand that the data is being moved from table 36 to table 112. The report that I'm calling is based on table 112. I'm passing only the Invoice Number from Salesheader variable. Debugging, Saleshaeader still has the correct "Last Posting No.". In codeunit CreateEmail.CreateInvoice I have the following code:
    CLEAR(InvoiceAsEmail);
    SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
    InvoiceAsEmail.USEREQUESTFORM :=FALSE;
    InvoiceAsEmail.SETTABLEVIEW(SalesInvoiceHeader.);
    InvoiceAsEmail.SAVEASHTML('C:\Somedirectory');
    

    Still cannot make work.Thank you in advance
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Some things to check:
    -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.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    kriki wrote:
    Some things to check:
    -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.

    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.

    ](*,) ](*,) :(:(
  • Options
    krikikriki Member, Moderator Posts: 9,090
    3. Are you sure it is an error or is it just a message?
    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).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    kriki wrote:
    3. Are you sure it is an error or is it just a message?
    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).

    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.
  • Options
    deniliadenilia Member Posts: 23
    The error messages appers when navision is trying to refresh the Sales Order screen to get the next Order no. the Form quits on me.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    denilia wrote:
    The error messages appers when navision is trying to refresh the Sales Order screen to get the next Order no. the Form quits on me.
    I suppose you put the code somewhere on a trigger of the form.
    After all code has been executed, put a CurrForm.UPDATE(FALSE);
    and lets see if this helps.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    kriki wrote:
    denilia wrote:
    The error messages appers when navision is trying to refresh the Sales Order screen to get the next Order no. the Form quits on me.
    I suppose you put the code somewhere on a trigger of the form.
    After all code has been executed, put a CurrForm.UPDATE(FALSE);
    and lets see if this helps.

    I put it after execution of Post and print. Still the same problem.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Lets go step-by-step:
    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)
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    1. Created another CU to call email function with eisting invoice. works fine.
    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.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    denilia wrote:
    1. Created another CU to call email function with eisting invoice. works fine.
    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.
    Did you do a post+print? Or just a print?
    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).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    Yes, i was trying to do Post and Print. I did leave the code only to generate a report(no emailing). I get the same error.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    denilia wrote:
    Yes, i was trying to do Post and Print. I did leave the code only to generate a report(no emailing). I get the same error.
    And the debugger doesn't show you where the error is?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    kriki wrote:
    denilia wrote:
    Yes, i was trying to do Post and Print. I did leave the code only to generate a report(no emailing). I get the same error.
    And the debugger doesn't show you where the error is?

    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.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    You got me an anoying problem. Lets try this:
    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.
    SalesPost.RUN(SalesHeader);
    MESSAGE('After SalesPost');
    GetReport(SalesHeader);
    MESSAGE('After GetReport');
    
    //Send Email
    IF Invoice THEN
      IF SalesHeader."Document Type" IN ["Document      Type"::Order,"Document Type"::"Credit Memo"] THEN
        CreateEmail.CreateInvoice(SalesHeader."Last Posting No.");
    MESSAGE('After CreateEmail.CreateInvoice');
    IF NOT FIND('>') THEN 
      IF FIND('<') THEN ;
    MESSAGE('After IF FIND');
    CurrFrom.UPDATE(FALSE);
    MESSAGE('After CurrFrom.UPDATE(FALSE);');
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    Sry Kriki for a such strange problem. The last message I see is MESSAGE('After GetReport'); it never gets to MESSAGE('After CreateEmail.CreateInvoice');. I put another message after SAVASEHTML

    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.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    So the problem is in the report "InvoiceAsEmail".

    Lets try this:
    CLEAR(InvoiceAsEmail);
    SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
    InvoiceAsEmail.USEREQUESTFORM :=FALSE;
    InvoiceAsEmail.SETTABLEVIEW(SalesInvoiceHeader.);
    InvoiceAsEmail.RUNMODAL;
    MESSAGE('GENERATED');
    
    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.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    deniliadenilia Member Posts: 23
    kriki wrote:
    So the problem is in the report "InvoiceAsEmail".

    Lets try this:
    CLEAR(InvoiceAsEmail);
    SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
    InvoiceAsEmail.USEREQUESTFORM :=FALSE;
    InvoiceAsEmail.SETTABLEVIEW(SalesInvoiceHeader.);
    InvoiceAsEmail.RUNMODAL;
    MESSAGE('GENERATED');
    
    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.

    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? ](*,) ](*,) ](*,) ](*,) ](*,) ](*,)
  • Options
    krikikriki Member, Moderator Posts: 9,090
    And this?
    LEAR(InvoiceAsEmail);
    SalesInvoiceHeader.SETRANGE("No.",InvoiceNo);
    InvoiceAsEmail.USEREQUESTFORM :=FALSE;
    InvoiceAsEmail.SETTABLEVIEW(SalesInvoiceHeader.);
    InvoiceAsEmail.SAVEASHTML('C:\Somedirectory\file.html');
    MESSAGE('GENERATED');
    
    If this gives an error, try to debug every single line. If you don't find it, I think I am out of options and probably it is a Navision bug.
    In this case, you need to try to create the error on a Cronus-DB and send it to Microsoft to fix it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.