Author info

Using External Assemblies in NAV 2009 reporting Part I

erstellt von Rene Gayer am 25. May 2010 21:43

Since NAV 2009 Service Pack 1 it is possible to use External Assemblies in NAV 2009 reports. This is a feature of Reporting Servicesand this feature was activated with Service Pack 1. Some weeks ago I tried to use an external assembly in NAV 2009 reporting. I want to figure out HOW to use it and what is possible. Now, I will give you step by step an overview what you have to do using external assemblies in NAV 2009 reporting.

Please note: My sample isn’t really a very cool report. More or less it should show you the way you have to go.

Goal: Create a simple report using an expression in RDLC which is returned by an external assembly

--------------------------------------

REQUIREMENTS

NAV 2009 (3 Tier ) Installation

Visual Studio Web Developer Express Edition (and reporting add-in)

Visual Studio C# Express Edition

Note: Claus already documented the supportability of Visual Studio 2010 with NAV 2009 Service Pack 1

--------------------------------------

B1.1.1 Write a simple class library in visual Studio

  • Start Visual Studio Express C#
  • Select New project ClassLibrary

clip_image002

  • Enter AssemblySample in the name field and select the OK button

clip_image004

Note: Now, before moving on developing the class library, we have to setup a very important assembly property for using the library in NAV 2009.

  • On the right side in the solution explorer look for the Assemblyinfo.cs file.

clip_image005

  • Double Click on it opens the appropriate information file

We have to insert the AllowPartiallyTrustedCallers property in our solution. Without it, calling the assembly in NAV 2009 would run into an security error.

  • Insert the [assembly: AllowPartiallyTrustedCallers] in the AssemblyInfo file
  • Insert the System.Security Reference which is the base class for this property

clip_image007

  • Return to the Class1.cs file by using the solution explorer once again.

Let’s start writing the c# code for building a specific function in our library. As I already mentioned this report will not create a cool “wow” effect report.  It should more or less show you the possibilities. Because of this I will write a function for generating a random password for each user in NAV and print out this information.

Note: If you don’t want to use the sample below, just use public string Test(){return "it works";} instead of my source code.

 

  • Please insert the source code and functions below in your project

Function 1 – generates a random number (ok is also possbile in NAV ;)

--------------------------------------

private int RandomNumber(int min, int max)
{Random random = new Random();
return random.Next(min, max); }

--------------------------------------

Function 2 – generates a random string

--------------------------------------

private string RandomString(int size, bool lowerCase)
{StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{ ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch); }
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();}

--------------------------------------

Function 3 – PUBLIC! – this is the one we will use in the NAV 2009 report for generating a password for the user

--------------------------------------

public string GetPassword()
{
StringBuilder builder = new StringBuilder();
builder.Append(RandomString(4, true));
builder.Append(RandomNumber(1000, 9999));
builder.Append(RandomString(4, false));
return builder.ToString(); -> This later should be the value which is returned to NAV 2009
}

image

to be continued ….

Comments

>

6/1/2010 8:17:08 PM #

Using External Assemblies in NAV 2009 reporting Part III/III

B1.2 Create a report in NAV 2009 using the external assembly Try to remember once again: The goal is

DynamicsBlog

>

6/1/2010 11:26:55 PM #

Pingback from helpwomans.ru

insert into builder «  Ð­Ñ…о блогосферы

helpwomans.ru

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Disclaimer | Impressum
BlogEngine.NET 1.5.0.7 powered by atwork