mibuso.com

Microsoft Business Solutions online community
It is currently Fri May 24, 2013 6:19 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How do I run a report from a Codeunit with certain options?
PostPosted: Wed Feb 22, 2012 2:34 am 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
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!

_________________
Joseph Dewey
Microsoft Dynamics NAV User


Top
 Profile E-mail  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Wed Feb 22, 2012 2:38 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
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.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Wed Feb 22, 2012 2:41 am 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
So there is no other way?

_________________
Joseph Dewey
Microsoft Dynamics NAV User


Top
 Profile E-mail  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Wed Feb 22, 2012 3:38 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Fri Jun 11, 2004 9:05 pm
Posts: 4858
Location: Los Angeles, CA
Country: United States (us)
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


Top
 Profile E-mail WWW  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Wed Feb 22, 2012 4:24 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
That report already IS processing only. He doesn't have the rights to modify it.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Mon Feb 27, 2012 4:16 pm 
Offline

Joined: Thu Oct 30, 2008 10:38 am
Posts: 987
Location: Earth
Country: Netherlands (nl)
To answer your question
josephdewey 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.

_________________
|Pressing F1 is so much faster than opening your browser|
|MCBMSS: 5.0 intro|MCTS:NAV09 839..841|JetReports© Certified Specialist|
|Dynamics Anywhere: Mobile Business Solutions|


Last edited by Sog on Tue Feb 28, 2012 10:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Mon Feb 27, 2012 11:08 pm 
Offline

Joined: Sat Jan 28, 2012 4:48 pm
Posts: 56
Country: Netherlands (nl)
josephdewey wrote:
And specifically, I want to have the "Post to G/L" checked when I run this report.

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. Setup


Top
 Profile  
 
 Post subject: Re: How do I run a report from a Codeunit with certain optio
PostPosted: Tue Apr 03, 2012 3:16 am 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
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.

Code: Select all
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 User


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: