How do I run a report from a Codeunit with certain options?
josephdewey
Member Posts: 87
I'm trying to call a report from within a Codeunit, and I want certain options to populate on the Options tab. Specifically, it's report 795, Adjust Cost - Item Entries, but I actually have this question for any report. And specifically, I want to have the "Post to G/L" checked when I run this report.
I know a good way of doing this is making a function in the report called Initialize with the variables as parameters, and then I can call this function from the Codeunit, before I run the report from the Codeunit.
The problem is that I can't modify 795, because I'm not a partner (Item Ledger Permissions error), so I'm wondering if there's another way to call 795 (or other reports) with specific options, without modifying the report.
Thanks in advance!
I know a good way of doing this is making a function in the report called Initialize with the variables as parameters, and then I can call this function from the Codeunit, before I run the report from the Codeunit.
The problem is that I can't modify 795, because I'm not a partner (Item Ledger Permissions error), so I'm wondering if there's another way to call 795 (or other reports) with specific options, without modifying the report.
Thanks in advance!
Joseph Dewey
Microsoft Dynamics NAV User
Microsoft Dynamics NAV User
0
Comments
-
That report needs to be modified to either set default values automatically, or to have functions that accept them as parameters. If you don't have permission to do it in your license, you'll have to get your partner involved to do it for you.0
-
So there is no other way?Joseph Dewey
Microsoft Dynamics NAV User0 -
Instead of a codeunit, you can use a process only report that runs without user prompts.Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
That report already IS processing only. He doesn't have the rights to modify it.0
-
To answer your questionjosephdewey wrote:The problem is that I can't modify 795, because I'm not a partner (Item Ledger Permissions error), so I'm wondering if there's another way to call 795 (or other reports) with specific options, without modifying the report.
The answer is no, without modifications a report's option can't be specified from another object (codeunit, report,...) unless a function is already available.0 -
If you are calling the report with use of request window then "Post to G/L" will be checked when you check "Automatic Cost Posting" in Inv. Setupjosephdewey wrote:And specifically, I want to have the "Post to G/L" checked when I run this report.0 -
I was able to do it with the following code.
The only problems are that you have to mark "Automatic Cost Posting" as False, and the second report prints out some output.OBJECT Codeunit 50047 Run Adjust Cost Reports { OBJECT-PROPERTIES { Date=03/28/12; Time=11:24:41 AM; Modified=Yes; } PROPERTIES { OnRun=BEGIN CostReports; END; } CODE { PROCEDURE CostReports@1240520003(); VAR AdjustCostReport@1240520004 : Report 795; PostCostReport@1240520003 : Report 1002; InventorySetup@1240520005 : Record 313; TEXT01@1240520006 : TextConst 'ENU=Automatic Cost Posting must be FALSE to run this Codeunit'; BEGIN InventorySetup.GET(); IF InventorySetup."Automatic Cost Posting" = TRUE THEN ERROR(TEXT01); AdjustCostReport.InitializeRequest('',''); AdjustCostReport.USEREQUESTFORM(FALSE); AdjustCostReport.RUNMODAL; PostCostReport.InitializeRequest(1, '', TRUE); PostCostReport.USEREQUESTFORM(FALSE); PostCostReport.RUNMODAL; MESSAGE('Cost Posting Finished'); END; } }Joseph Dewey
Microsoft Dynamics NAV User0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
