Options

Running report from the OnModify trigger

babbab Member Posts: 65
I have a problem, when running a report from the OnModify trigger of a table.
The situation is: when a record changes i need to send a notyfication e-mail. The attachment is a html file generated by a report.
When I run a report (SAVEASHTML) from the OnModify trigger, it seems, that the report runs the OnModify trigger of the table, and falls is recursion.
I tried it on several tables/reports.
Has anybody met this problem?

Answers

  • babbab Member Posts: 65
    Nobody met this problem?
    Other things: SQL2005, and NAV400 without any SP.
  • ClausHamannClausHamann Member Posts: 80
    Hi bab

    I just tried to save a report as htlm from the OnModify trigger and my computer locked up. It took my 5-10 minutes to kill Navision.

    I don't know what is happening and I won't repeat the test :D

    I guess we can conclude that we shouldn’t try to save reports as html from the OnModify trigger. Have you tried to solve the issue differently?

    You could just send a email from the OnModify trigger and then link to the report or include the required information in the body of the email.

    Regards

    Claus
  • babbab Member Posts: 65
    Yes, I think I will send a simple e-mail, but the reason was, why I tried to do this way, because if I send a report by mail, the SalesPerson doesn't need to login to navision.
    Anybody else can solve this problem?
  • ara3nara3n Member Posts: 9,258
    Create a function on sales line called skipsendingreport. In the function set a global variable DONNOTSENDREPORT to true.
    Before running the modify(true) statement call the function.
    In onmodify trigger run the report only if DONNOTSENDREPORT is set to false.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • babbab Member Posts: 65
    I tried it several times, it does not work.
    My last try was:
    ReportSended: Boolean (Global scope)
    OnModifyRecord trigger of the form (SourceTable: T5050 (Contact)):
    run the report if the ReportSended is FALSE, and set it TRUE.
    And what i thought is impossible: it falls in recursion too. It seems, that the report runs this trigger too, and the "IF NOT ReportSended THEN" takes no effect... :?:
  • ara3nara3n Member Posts: 9,258
    create a field then on the line and modify it to true once you've sent the email. Only send the email if field is checked false.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • babbab Member Posts: 65
    Maybe it works, but this is only a half solution: When will this field became FALSE?
  • ara3nara3n Member Posts: 9,258
    hmm in your report you can do a modify without the true paramater.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • babbab Member Posts: 65
    I will try it, and post the result here.
    thx
  • babbab Member Posts: 65
    Finally it works :!:
    Added a new Field in the T5050 (Contact) Notification Sent - Boolean
    Created a report (Contact - Card), in the OnAfterGetRecord trigger:
    "Notification Sent" := FALSE;
    MODIFY;
    
    Added a new function - NotifyByMail to the T5050:
    Contact.RESET;
    Contact.SETRANGE("No.", "No.");
    FileName := ENVIRON('TEMP') + '\' + DELCHR(USERID, '=', ' ') + '.html';
    IF FILE.EXISTS(FileName) THEN
      FILE.ERASE(FileName);
    ContactCard.SETTABLEVIEW(Contact);
    "Notification Sent" := TRUE;
    ContactCard.SAVEASHTML(FileName);
    SMTPMail.NewMessage('noreply@xx.xx', STRSUBSTNO(Text80000, USERID, "No."));
    SMTPMail.SetWorkMode;
    SMTPMail.SetHost(CompanyInfo."SMTP Server");
    SMTPMail.AddLine(Text80001);
    SMTPMail.SetToAdress(SalesRecSetup."Notify Email on Contact Change");
    SMTPMail.AddAttachment(FileName);
    SMTPMail.Send;
    FILE.ERASE(FileName);
    

    In the OnModify trigger of the table:
    IF NOT "Notification Sent" THEN
      NotifyByMail;
    

    Thanks all!
  • ara3nara3n Member Posts: 9,258
    =D>
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.