Академический Документы
Профессиональный Документы
Культура Документы
December 2010
Contents
Developer Updates for Microsoft Dynamics NAV 2009 R2 ............................................................. 1
Viewing the Definition of a Function or Object by Using Go To Definition ................................... 2
Locking and Unlocking Objects .................................................................................................... 9
How to: Lock an Object ........................................................................................................... 10
How to: Unlock an Object ....................................................................................................... 11
How to: Integrate Classic Client Report Designer and Visual Studio Report Designer ............. 12
Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability ........... 14
Calling .NET Framework Members from C/AL Code.............................................................. 15
How to: Call .NET Framework Members from C/AL Code .................................................. 18
How to: Set .NET Framework Types to Target the RoleTailored Client or Microsoft
Dynamics NAV Server ..................................................................................................... 21
.NET Framework and C/AL Type Mappings ........................................................................... 23
Using .NET Framework Arrays ............................................................................................... 26
Using .NET Framework Collections ........................................................................................ 30
Using .NET Framework Enumerations ................................................................................... 31
Using .NET Framework Generics ........................................................................................... 33
Using .NET Framework Interfaces.......................................................................................... 35
Calling External Web Services with Windows Communication Foundation ........................... 36
How to: Add a FactBox on a Page Using the Wizard ................................................................ 38
How to: Use the System Indicator .............................................................................................. 40
Developer Updates for Microsoft Dynamics NAV
2009 R2
This document describes the new developer tasks that you can perform in Microsoft Dynamics NAV 2009
R2.
For more information about whats new in Microsoft Dynamics NAV 2009 R2, including whats new in the
application, see Whats New in Microsoft Dynamics NAV 2009 R2 in the MSDN Library. You can also find
this content in the Whats New in Microsoft Dynamics NAV 2009 R2.pdf file, which is located in the
Documentation folder. By default, this folder is C:\Program Files\Microsoft Dynamics
NAV\60\Documentation.
For more information about the hotfixes and known issues in Microsoft Dynamics NAV 2009 R2, see the
Microsoft Dynamics NAV 2009 R2 Release Notes (requires PartnerSource login). You can also find the
release notes in the ReadMe.htm file on the installation media.
In This Section
Viewing the Definition of a Function or Object by Using Go To Definition
Locking and Unlocking Objects
How to: Integrate Classic Client Report Designer and Visual Studio Report Designer
Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability
How to: Add a FactBox on a Page Using the Wizard
How to: Use the System Indicator
From the C/AL Globals window, select a user-defined The C/AL Editor goes to the C/AL code that defines the
function selected function.
From the C/AL Editor, select a user-defined function The C/AL Editor goes to the C/AL code that defines the
selected function.
From the C/AL Editor, select a user-defined function that The object is opened in the corresponding designer.
is called on an object variable A new C/AL Editor window opens to the C/AL code
that defines the selected function.
From the C/AL Editor, select a system function on an If the system function is called on an object variable, such
object as a record, codeunit, or report, then the object is opened
in the corresponding designer. If the system function is
not called on an object variable, then nothing happens.
From the C/AL Editor, select a variable that is one of the The object is opened in the corresponding designer or
following object types: editor:
Record Table Designer
Page Page Designer
Form Form Designer
Report Report Designer
Codeunit C/AL Editor
Dataport Dataport Designer
XMLport XMLport Designer
Note
If you select a variable that is a fundamental
data type, such as Integer or Decimal, then
information about the variable is displayed in the
status bar.
The result is that the C/AL Editor jumps to the C/AL code that defines the selected function.
The result is that the C/AL Editor jumps to the C/AL code that defines the selected function.
The result is that the object on which the function is called is opened in the corresponding designer and a
new C/AL Editor window opens to the C/AL code that defines the selected function.
If the system function is called on a record variable, then the table that the record is from is opened in
Table Designer.
If the system function is the <codeunit>.RUN function, then the codeunit is opened in a new C/AL Editor
window.
Permissions
To go to a definition, you must have the correct permissions. If you do not have permission to view the
definition of an object by selecting the object in Object Designer and then clicking Design, then you
cannot view it with the Go To Definition option.
Object Table
The information in the Locked and Locked By columns is stored in the Object table. The Object table is
a system table that stores information about objects in the application.
Concurrency Considerations
Even though you can lock objects, it is still possible for developers to have concurrency issues, as shown
in the following examples.
A developer opens an object in the designer but does not lock it. The developer makes several
changes to the object and saves the changes periodically. At the same time, a second developer
locks the object, and the first developer cannot save design changes to the object. The first developer
gets an error message that the object is locked by the second developer.
A developer locks an object. A second developer opens the locked object in read-only mode, and
then the first developer unlocks the object. The second developer still cannot save design changes to
the object even though the object is now unlocked because it is open in read-only mode.
See Also
How to: Lock an Object
How to: Unlock an Object
Tip
You cannot automatically unlock objects that you have locked. However, you can filter
for locked objects, select all objects that you have locked, and then unlock these
objects. For more information, see How to: Unlock an Object.
Note
If you go to the definition of an object, then the object is opened in design mode.
Therefore, if you set the Auto-Lock on Design field and then go to the definition of an
object, then the object is locked. For more information, see Viewing the Definition of a
Function or Object by Using Go To Definition.
See Also
How to: Unlock an Object
Locking and Unlocking Objects
To unlock an object
1. In the Classic client, on the Tools menu, click Object Designer.
2. In Object Designer, select one or more objects that you have locked, and then do one of the
following steps:
Right-click the object or objects, and then click Unlock.
On the File menu, click Unlock.
Press CTRL+ALT+U.
Note You must have the SUPER user role to force unlock an object.
See Also
How to: Lock an Object
Locking and Unlocking Objects
To work with both Object Designer and Visual Studio Report Designer
1. In the Classic client, on the Tools menu, click Object Designer.
2. To either create or modify an RDLC report, do one of the following steps:
To create a new RDLC report layout for a report, in Object Designer, click Report, select
the report, and then click Design. On the Tools menu, click Create Layout Suggestion.
To modify an existing RDLC report layout for a report, in Object Designer, click Report,
select the report that you want to modify, and then click Design. On the View menu, click
Layout.
3. After you make changes in the RDLC layout, in Visual Studio, on the File menu, click Save
Report.rdlc.
4. In the Classic client, select an empty line in the report in Report Designer. A dialog box opens
with the following message:
The layout of report id: '<report ID>' is changed by another application.
Filename of the changed RDLC: <filename>
Do you want to load the changes?
Note
If you try to close the report in Object Designer in the Classic client, then you see the
following error: You must close the Visual Studio Designer window before closing
the report object.
Note
If you try to view the layout when the report layout is already open, then you see the
following error: The report layout is already open in Visual Studio.
8. In Classic client Report Designer, make some additional changes to the report dataset.
9. In the Classic client, on the File menu, click Save.
10. In the Save dialog box, select Compiled, and then click OK.
Important
If you save the report but do not compile it or if you compile the report but do not save
it, then you cannot load the changes into the RDLC report layout in the following step.
You must both save and compile the report.
11. Go to Visual Studio Report Designer. You see the following message: This file has been
modified outside of the source editor. Do you want to reload it? Click Yes or Yes to All to
reload the changes from Classic client Report Designer into the RDLC report layout.
12. In Visual Studio, in the Website Data Sources pane, expand DataSet, right-click Result, and
then click Refresh. The additional items that you added to the dataset in Section Designer in
the Classic client are displayed in the Visual Studio dataset.
13. You can continue making changes in either Visual Studio Report Designer or Classic client
Report Designer without having to close either designer. You must save and compile the report
object after you make changes and load the changes into the report object or the RDLC report
layout when you are prompted.
See Also
Calling .NET Framework Members from C/AL Code
.NET Framework Type Conversion
Using .NET Framework Arrays
Using .NET Framework Collections
Using .NET Framework Enumerations
Using .NET Framework Generics
Using .NET Framework Interfaces
Calling External Web Services Using Windows Communication Framework
Constructors
A constructor is a method that creates an instance of an object and prepares it for use. Before you use a
DotNet variable, you should verify whether the variable is static or is an object instance because this
determines whether you have to use a constructor.
Static variables do not require a constructor because they do not have an instance.
Object instance variables require a constructor because they must be created before they can be
accessed.
To find the constructor and other methods and property for your object, in Object Designer, click Symbol.
C# Indexers
A C# indexer is represented as an Item property in C/AL. For example, in C#, the following code sets an
array element N to the value M:
arrayVariable[N] = M;
In C/AL, the corresponding code is as follows:
arrayVariable.Item(N) := M;
Indexers can also be overloaded. In Object Designer, click C/AL Symbol Menu to see the parameters
and return types for the indexer.
dotNetList1 := dotNetList1.List(5);
dotNetList2 := dotNetList2.List(10);
dotNetList3 := dotNetList3.List(5);
Tip
You can install the assembly in the global assembly cache with the GAC utility. For
more information, see GAC Utility in the MSDN Library.
2. In the Classic client, open Object Designer, and then open the object that will use .NET
Framework interoperability, such as the page or codeunit.
3. To open the C/AL code for the object, on the View menu, click C/AL Code.
4. To create the variable for .NET Framework interoperability, do one of the following steps:
To create a global variable, on the View menu, click C/AL Globals.
To create a local variable, on the View menu, click C/AL Locals.
Important
A local DotNet variable, including any resources that it references, is disposed after
the C/AL function to which it belongs is run.
5. On the Variables tab, in the Name field, type a name for the variable.
6. Set the DataType field to DotNet.
7. In the SubType field, click the AssistEdit button to open the .NET Type List window.
8. In the Assembly field, click the AssistEdit button to open the Assembly List window.
9. If the assembly that you want to reference is in the global assembly cache, then click the .NET
tab. If the assembly is in the Add-ins folder of your Microsoft Dynamics NAV installation, then
click the Dynamics NAV tab.
10. In the list of assemblies, select the assembly, and then click OK to return to the .NET Type List
window.
If you do not see the assembly that you want, then make sure that you have installed it
correctly. For more information, see step 1 of this procedure.
11. In the .NET Type List window, select the type that contains the member that you want to call
from the Microsoft Dynamics NAV object, and then click OK.
The .NET Type List window displays all available types, including classes, enumerations,
structs, and interfaces, which are available in the selected assembly.
By default, variables are set to run the assembly instance on Microsoft Dynamics NAV Server. If
you want to run the assembly instance on the RoleTailored client, see How to: Run a .NET
Framework Assembly on the RoleTailored Client or Server.
Note
Member names are case-sensitive. Also, constructor names that are longer than 30
characters are truncated after 30 characters.
4. Add the following code to call the methods or properties.
MyVariableName.MethodPropertyName(arguments);
The MethodPropertyName variable is the name of the method or property that you want to call,
and the arguments variable represents any arguments of the method or property.
Important
Some types in the System namespace of the .NET Framework class library are
automatically converted to C/AL types. You cannot assign values to .NET Framework
variables for these types. For more information, see .NET Framework Type Conversion.
Note
Methods can be overloaded. Therefore see the description at the bottom of the C/AL
Symbol Menu, which shows the parameter and return types for each method. Also,
method and property names that are longer than 30 characters will be truncated, and
you cannot compile the Microsoft Dynamics NAV object. For more information, see
Calling .NET Framework Members From C/AL Code
Example
Description
The following code example uses .NET Framework interoperability to display headlines from an RSS feed
from the Microsoft Dynamics NAV team blog, which has the following URL:
http://feeds.feedburner.com/MicrosoftDynamicsNavTeamBlog?format=xml.
This example calls members of the System.XML assembly, which is part of the Microsoft .NET
Framework class library and is installed in the global assembly cache.
i Integer
After you create the codeunit, add the following code to its OnRun trigger.
Code
xml := xml.XmlDocument();
xml.Load('http://feeds.feedburner.com/MicrosoftDynamicsNavTeamBlog?format=xml');
items := xml.SelectNodes('/rss/channel/item');
FOR i := 0 TO items.Count - 1 DO
BEGIN
title := items.Item(i).SelectSingleNode('title/text()');
MESSAGE( title.Value );
END
Comments
To see the example in the RoleTailored client, you can create an action on a page that opens the
codeunit.
See Also
Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability
Important
You cannot set different types of the same variable to target both the RoleTailored client and
Microsoft Dynamics NAV Server.
Note
You must copy the assembly to each computer running the RoleTailored client. If the
assembly is included in the global assembly cache, then you do not have to do this task.
Note
You can also put assemblies in a subfolder of the Add-ins folder. This can be useful
when you have multiple versions of the same assemblies and dependencies.
Note
If the assembly is included in the global assembly cache of the computer running Microsoft
Dynamics NAV Server, then you do not have to do this task.
To set the .NET Framework type to target Microsoft Dynamics NAV Server
1. In Object Designer, open the Microsoft Dynamics NAV object that uses .NET Framework
interoperability.
2. Do one of the following steps:
For a global variable, on the View menu, click C/AL Globals.
For a local variable, in the C/AL Editor, select the trigger that uses the DotNet variable, and
then on the View menu, click C/AL Locals.
3. On the Variables tab, select the NET Framework variable type, and then on the View menu,
click Properties.
4. In the Properties window, set the RunOnClient property to No.
To copy a .NET Framework assembly to the computer running Microsoft Dynamics NAV Server
On the computer running Microsoft Dynamics NAV Server, copy the .NET Framework assembly
to the Add-ins folder in the Microsoft Dynamics NAV Server installation folder.
By default, the path of the Microsoft Dynamics NAV Server installation folder is C:\Program
Files\Microsoft Dynamics NAV\60\Server\Add-ins.
Note
You can also put assemblies in a subfolder of the Add-ins folder. This can be useful
when you have multiple assemblies and dependencies.
See Also
Calling .NET Framework Members from C/AL Code
How to: Call .NET Framework Members From C/AL Code
System.Int16 Integer
(-32768..32767) (2,147,483,647)
System.Int32 Integer
(-2,147,483,648..2,147,483,647) (2,147,483,647)
System.Int64 BigInteger
(-9,223,372,036,854,775,808.. (9,223,372,036,854,775,807)
9,223,372,036,854,775,807)
System.Single Decimal
(3.402823e38) (3.402823e38)
System.Double Decimal
(1.79769313486232e308) (1.79769313486232e308)
System.Bool Boolean
(TRUE, FALSE) (TRUE, FALSE)
System.Guid GUID
(128-bit number) (128-bit number)
System.IO.Stream OutStream
See Also
Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability
Your C/AL code uses .NET Framework interoperability extensively, and you .NET Framework array
must share an array among many methods.
Your C/AL code mostly uses basic C/AL types and does not interoperate with C/AL array
the .NET Framework.
To use a .NET Framework array in C/AL, you must use the System.Array class in the .NET Framework
class library, which is the class from which all arrays inherit. When interfacing with an array in C/AL, you
must use the following methods of the System.Array class to create and access elements in the array.
Method Description
Many .NET Framework classes implement these methods. Therefore, they are available for you to use in
C/AL code. If you are writing your own .NET Framework code and want to use it in Microsoft Dynamics
NAV, then you must implement these methods yourself.
In C/AL, some .NET Framework data types, such as strings, integers, and decimals, are automatically
converted to C/AL types. If a .NET Framework array contains these data types, then you create an
assembly that contains methods that return the information about the data types and then reference the
assembly in the C/AL code. This concept is illustrated in the following examples.
return typeof(Int32);
}
}
arraySize Integer
i Integer
alData Integer
4. On a trigger of the Microsoft Dynamics NAV object, add the following C/AL code to create, fill, and
implement the array.
// Sets the number of elements in the .NET Framework array.
arraySize := 10;
// Creates an instance of the .NET Framework array that contains the Int32 type.
clear(varDotNet);
// Gets the array data and validates the content. The object that is returned by
BEGIN
alData := varArray.GetValue(i);
error('Invalid array data in element %1, expected %2, actual %3', i, i+100,
alData);
END;
Data = value;
}
2. Build the project, and then copy the assembly to the Add-ins folder of the Microsoft Dynamics NAV
installation folder. By default, the path of the installation folder is C:\Program Files\Microsoft
Dynamics NAV\60\Classic.
3. In the Classic client, open a Microsoft Dynamics NAV object, open the C/AL code, and then create
the following C/AL variables.
Variable name DataType SubType
arraySize Integer
i Integer
alData Integer
4. On a trigger of the Microsoft Dynamics NAV object, add the following C/AL code to create, fill, and
implement the array.
arraySize := 10;
// can be retrieved.
varDotNet := varDotNet.WrapInt32(1);
// user-defined type.
clear(varDotNet);
BEGIN
varDotNet := varDotNet.WrapInt32(i+100);
varArray.SetValue(varDotNet,i);
END;
BEGIN
varDotNet := varArray.GetValue(i);
// Gets the integer value from the .NET Framework object using the Data property.
alData := varDotNEt.Data;
error('Invalid array data in element %1, expected %2, actual %3', i, i+100,
alData);
END;
See Also
Calling .NET Framework Members from C/AL Code
How to: Call .NET Framework Members From C/AL Code
.NET Framework Type Conversion
Example
The following example implements the System.Collections.ArrayList interface and uses the
GetProcesses method from the System.Diagnostics.Process type to display a list of process IDs in
message boxes. Although this is not a typical example for an ERP product such as Microsoft Dynamics
NAV, it shows the flexibility that you get with the .NET Framework.
The example requires that you define the following C/AL variables.
Variable name DataType SubType
I Integer
MyProcessList := Process.GetProcesses();
BEGIN
Process := MyProcessList.GetValue(I);
MESSAGE(FORMAT(Process.Id));
END;
See Also
.NET Framework Type Conversion
How to: Call .NET Framework Members From C/AL Code
Example
This example shows how to use an enumeration in integer expressions in C/AL and then convert the text
string back to an integer to store it in the enumeration variable. In the following C# example, the
enumeration is contained in the Microsoft.Dynamics.Nav.EnumSample assembly.
namespace Microsoft.Dynamics.Nav.EnumSample;
Item1,
Item2,
Item3,
Item4
};
}
In the Microsoft Dynamics NAV object, define the following C/AL variables.
Variable name DataType SubType Length
formatResult Text 30
alInteger Integer
To handle the enumerator type, add the following code to a C/AL function.
// Assign an integer to the .NET Framework enumeration.
varDotNet := 2;
formatResult := format(varDotNet);
if formatResult <> 'Item3' then
// Assuming that the enum value is stored as a text string, convert it back to the
// The varDotNet enum should now contain the integer value 3 and the enum 'Item4'.
alInteger := varDotNet;
error('Wrong enumeration integer value. Expected %1, but actual was %2.', 3, alInteger);
formatResult := format(varDotNet);
error('Wrong enumeration value. Expected %1, actual was %2.', 'Item4', formatResult);
See Also
Calling .NET Framework Members from C/AL Code
How to: Call .NET Framework Members From C/AL Code
.NET Framework Type Conversion
Example
The following example constructs a string list, fills the list with data, and then uses the Item method to
validate whether the list contains the expected data. The Item method is equivalent to a C# index
operator.
textResult Text 30
i Integer
capacity Integer
capacity := 5;
varDotNet := varDotNet.List(capacity);
See Also
Calling .NET Framework Members from C/AL Code
How to: Call .NET Framework Members From C/AL Code
Example
In the following C# example, you have the Sample class that explicitly implements the ISample interface.
class Sample : ISample
...
string ISample.Name()
...
}
To call the ISample.Name method from C/AL code, you create the following variables.
Variable name DataType SubType (simplified)
After you create the variables, add the following code that assigns the class variable to the interface
variable and then calls the interfaces method.
// Assigns the class variable to the interface variable.
ivar := cvar;
...
ivar.Name();
...
navBinding := navBinding.BasicHttpBinding;
navBinding.Security.Mode := 4;
address :=
'http://localhost:7047/DynamicsNAV/WS/CRONUS%20International%20Ltd./Page/SalesOrder';
navBinding.Security.Transport.ClientCredentialType := 4; //
salesOrderService := salesOrderService.SalesOrder_PortClient(navBinding,
endpointAddress.EndpointAddress(address);
salesOrderService.ClientCredentials.Windows.AllowedImpersonationLevel := 4;
salesOrder := salesOrderService.Read('10000');
See Also
Calling .NET Framework Members from C/AL Code
How to: Call .NET Framework Members From C/AL Code
You typically use a FactBox to display information that is related to an item on the main content page. For
example, on a page that shows a sales order list, you can use a FactBox to show customer details for a
selected sales order in the list.
A FactBox is divided into one or more parts that are arranged vertically. Each part can contain one of the
following objects:
Page of the CardPart or ListPart type.
Chart.
System part, including Microsoft Outlook, Notes, MyNotes, or RecordLinks.
Using the wizard, you can add a FactBox on the following page types:
Card
Document
Note
If you want to add a FactBox without using the wizard, see Walkthrough: Adding a FactBox to the
Customer List Page in the MSDN Library.
Note
When you are in configuration mode, the
Configuration status is always displayed. You
cannot turn this text off.
Custom Text Shows text that you enter in the System Indicator Text field.
Company Information Shows text that you enter in the Name field.
Company+Database Shows the company name, the middle-tier host name, and the
database name.
4. In the System Indicator Style field, select from the Standard and Accent1 through Accent9
options to add a certain style to the system indicator.
5. In the System Indicator Text field, enter custom text to show. To show the text, you must
select the Custom Text option in the System Indicator field.
6. Click OK, and then exit and open the RoleTailored client to see the changes.
The information contained in this document represents the current view of Microsoft Corporation on the issues discussed
as of the date of publication. Because Microsoft must respond to changing market conditions, this document should not be
interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information
presented after the date of publication.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no
part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by
any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express
written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering
subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the
furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual
property.