Email Notifier

Mike_HWG
Member Posts: 104
Hey all,
I thought I had a brilliant idea today, but I think I ran into a brick wall.
My idea was to have a report (or codeunit, doesn't matter) that you could specify a report to run. Once that report completed, my code would send me an email notification.
Unfortunately, NAV doesn't transfer control back to my code until after the called report is closed... is there a way around this?
I thought I had a brilliant idea today, but I think I ran into a brick wall.
My idea was to have a report (or codeunit, doesn't matter) that you could specify a report to run. Once that report completed, my code would send me an email notification.
Unfortunately, NAV doesn't transfer control back to my code until after the called report is closed... is there a way around this?
Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)
Systems Analyst
NAV 2009 R2 (6.00.34463)
0
Answers
-
My current solution works great for processing only reports and dataports.
Though I haven't tried it, it should work fine with reports that you send to a printer.
The only problem is reports that you wish to preview... but you gave me an idea. Users can simply print the report to a PDF printer! =D> Thank you for the idea!
The goal of the code was for it to work with any report WITHOUT having to modify the target report... I think I've done it well enough that I can release it to my users.
Here's my code, hope others may benefit as well. Please respond here with any improvements!
WARNING: This functionality exposes ALL reports and dataports to the user, INCLUDING objects that are not visible to the user on the Navigation Pane! At this time, only Super Users should have access to this object!!OBJECT Report 50094 Email Notifier { OBJECT-PROPERTIES { Date=11/25/11; Time=[ 2:41:36 PM]; Modified=Yes; Version List=HW322x; } PROPERTIES { ProcessingOnly=Yes; OnPreReport=BEGIN IF Object.Name = '' THEN ERROR(txtNoObject); END; OnPostReport=BEGIN Subject := STRSUBSTNO(txtComplete,Object.ID,Object.Name); Body := STRSUBSTNO(txtBody,Subject,SenderAddress); Subject := txtSubject + Subject; SMTPMail.CreateMessage('',SenderAddress,Recipients,Subject,Body,FALSE); SMTPMail.CreateMessage('',SenderAddress,Recipients,Subject,Body,FALSE); CASE ObjectType OF ObjectType::Report: REPORT.RUNMODAL(Object.ID,TRUE); ObjectType::Dataport: DATAPORT.RUNMODAL(Object.ID,TRUE); END; SMTPMail.Send; END; } DATAITEMS { } REQUESTFORM { PROPERTIES { Width=9130; Height=3080; } CONTROLS { { 1000000004;TextBox;3410 ;0 ;2310 ;440 ;InPage=-1; CaptionML=ENU=Object Type; SourceExpr=ObjectType; OnAfterValidate=BEGIN CLEAR(Object); END; } { 1000000005;Label ;0 ;0 ;3300 ;440 ;ParentControl=1000000004; InPage=-1 } { 1000000006;TextBox;3410 ;550 ;5720 ;440 ;Name=ctrl_ObjectID; InPage=-1; CaptionML=ENU=Object; SourceExpr=Object.Name; OnLookup=BEGIN CASE ObjectType OF ObjectType::Report: Object.SETRANGE(Type,Object.Type::Report); ObjectType::Dataport: Object.SETRANGE(Type,Object.Type::Dataport); END; IF FORM.RUNMODAL(358,Object) = ACTION::LookupOK THEN Text := Object.Name ELSE EXIT(FALSE); EXIT(TRUE); END; } { 1000000007;Label ;0 ;550 ;3300 ;440 ;ParentControl=1000000006; InPage=-1; CaptionML=ENU=Object } { 1000000008;TextBox;3410 ;1100 ;5720 ;440 ;InPage=-1; CaptionML=ENU=Sender Email; SourceExpr=SenderAddress } { 1000000009;Label ;0 ;1100 ;3300 ;440 ;ParentControl=1000000008; InPage=-1 } { 1000000012;TextBox;3410 ;1650 ;5720 ;440 ;InPage=-1; CaptionML=ENU=Recipient Email(s); ToolTipML=ENU=Separate addresses with a comma; SourceExpr=Recipients } { 1000000013;Label ;0 ;1650 ;3300 ;440 ;ParentControl=1000000012; InPage=-1; ToolTipML=[ENU="Separate addresses with a semicolon (;)"] } { 1000000000;Label ;0 ;2200 ;9130 ;880 ;InPage=-1; MultiLine=Yes; LeaderDots=No; CaptionML=ENU=For printable reports, please redirect your output to a virtual PDF printer } } } CODE { VAR ObjectType@1000000000 : 'Report,Dataport'; Object@1000000010 : Record 2000000001; SenderAddress@1000000003 : Text[100]; Recipients@1000000004 : Text[1024]; txtSubject@1000000008 : TextConst 'ENU="NAV Automated Notification: "'; txtComplete@1000000005 : TextConst 'ENU=%1: %2 Processing is Complete'; txtBody@1000000007 : TextConst 'ENU=This is an automated email reminding you that %1. Thank you,%2'; Subject@1000000001 : Text[200]; Body@1000000002 : Text[1024]; SMTPMail@1000000009 : Codeunit 400; txtNoObject@1000000006 : TextConst 'ENU=You must choose an object to run!'; BEGIN { HW322, 11/23/11, MJH - Initial Creation. Note that it only works for processingonly reports or for dataports. For printable reports, please redirect to a virtual PDF printer. Note that CASE statements were used if there is a future need for other object type handling. } END. } }
Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0 -
Mike_HWG wrote:Here's my code, hope others may benefit as well.Andwian wrote:How about print the report to PDF, XLS, and then freely close the report?Regards,
Andwian0 -
Andwian wrote:Andwian wrote:How about print the report to PDF, XLS, and then freely close the report?Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0 -
Just discovered one issue #-o
WARNING: This functionality exposes ALL reports and dataports to the user, INCLUDING objects that are not visible to the user on the Navigation Pane! At this time, only Super Users should have access to this object!!
I currently don't have an easy solution for this.Michael Hollinger
Systems Analyst
NAV 2009 R2 (6.00.34463)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions