Book Image

Microsoft Dynamics AX 2012 R3 Security

By : Ahmed Mohamed Rafik Moustafa
Book Image

Microsoft Dynamics AX 2012 R3 Security

By: Ahmed Mohamed Rafik Moustafa

Overview of this book

Table of Contents (12 chapters)

Introducing the MorphX development tool


Microsoft Dynamics AX includes a set of tools, and one of the most powerful is the MorphX development tool, which you can use to build and modify Microsoft Dynamics AX business applications. With the MorphX tool, you can create, view, modify, and delete the application model elements that contain metadata, structure, properties, and X++ code, such as tables, fields, indexes, relations, methods, and so on.

To illustrate the concept of MorphX, assume that you have the license to Microsoft Dynamics AX and you need to edit and develop any object in the standard ERP package. Therefore, this development tool will help you extend the existing functionality to fit your organization's requirements and needs as used by Microsoft to develop the application modules.

You can access these development tools from the following places:

  • In the development workspace's Tools menu

  • In the context menu of elements in Application Object Tree (AOT)

Note

To enable the development mode in Microsoft Dynamics AX 2012, press Ctrl + Shift + W to launch the development workspace.

The following table lists the MorphX tools and their purpose:

Tool

Purpose

AOT

This is the core of all development processes and activities. All application objects are stored in a tree organized by the object type.

X++ code editor

Inspects and writes X++ source code.

Compiler

Compiles X++ code into an executable format.

Debugger

Finds bugs in X++ code.

Projects

Groups related elements into projects.

The property sheet

The property sheet shows keys and values. The main purpose is to inspect and modify properties of elements.

The label editor

Creates and inspects localizable strings.

The cross-reference tool

Determines where an element is used.

The Find tool

Searches for code or metadata patterns in the AOT.

The table browser tool

Views the contents of a table directly from a table elements..

The best practices tool

Detects defects in the code and the elements.

The reverse engineering tool

Generates the Unified Modeling Language (UML) element or entity relationship diagrams (ERDs) to be uses in MS Visio.

Application Object Tree

The AOT is the main development menu in Microsoft Dynamics AX. It is easy to navigate through the AOT using the arrows keys on the keyboard.

The root of AOT contains element categories such as:

  • Data Dictionary

  • Classes

  • Tables

  • Forms

  • Macros

  • Parts

  • Data Sets

  • SSRS Reports

  • Reports

Note

Before practicing effectively on AOT, understand the naming structure of all elements. There are thousands of elements that exist in AOT.

The elements are arranged alphabetically and named by the following structure:

(Business Area Name) + (Functional Area) + (Action Performed or Type of Content)Ex: CustPaymReconciliationImportBusiness Area: Cust = Customer

Functional Area: PaymReconciliation = Payment Reconciliation

Action Performed: Import = Import

The element categories are shown in the following screenshot:

You can create elements in the AOT node by following the next steps:

  1. Right-click on the element category node.

  2. Select New <Element Type>.

When you create a new element, generated names are automatically given, and you can replace the default name with a new name.

The X++ code editor

The X++ code editor is a text editor that contains multiple features that you can find in Visual Studio, such as scripting, multiediting, word completion, and so on.

You can write all the X++ code with the X++ code editor by selecting a node in the AOT and pressing Enter. As shown in the following screenshot, the X++ editor contains two panes (the left-hand side pane and the right-hand side pane). The right pane shows the X++ code for the method selected in the left-hand side pane:

The following table lists the shortcut keys for the X++ code editor:

Shortcut keys

Action

F1

Shows the help window

F4

Goes to the next error

F5

Executes the current element

F7

Compiles

F9

Toggles a breakpoint

F12

Goes to the implementation (drilled down in the code)

Esc

Cancels the selection

Ctrl + X

Deletes the current selection

Ctrl + I

Incremental search

Ctrl + E, C

Comment selection

Ctrl + E, U

Uncomment selection

Ctrl + Tab

Goes to the next method

Ctrl + Shift + Tab

Goes to the previous method

Alt + R

Run and editor script

Alt + Shift + arrow keys

Enables block selection

Ctrl + Alt + Spacebar

Opens the Label editor

Ctrl + Shift + Spacebar

Shows the method parameter help

Ctrl + Shift + F9

Removes all breakpoints

The X++ code editor contains a set of editor scripts that you can invoke by clicking on the script icon on the X++ code editor toolbar, or you can type the name of the script + Tab in the editor. You will notice that there are built-in scripts such as:

  • Send to the file

  • Send to the mail recipient

  • Open the AOT for the element related to the method selected

  • Generate the code for standard code patterns such as the main, construct, and parm methods

Note

Parm is a short for parameter and is used as simple property getters and setters on classes.

You can create your own scripts by adding new methods to the EditorScripts class because the list of editor scripts is extendable.

Compiler

The X++ compiler is a bottleneck for anything you build or install in your own scenarios across the system modules; just as you should compile any programming language, the X++ compiler can compile your code and produce a lot of information such as compiler errors, compiler warnings, and tasks.

In earlier versions of Microsoft Dynamics AX, the compiling processes were designed in three phases:

  1. Declaration and method signatures.

  2. Metadata validation and p-code generation.

  3. Recompilation of elements that had preliminary errors.

Note

In earlier versions in Microsoft Dynamics AX, the phases were:

1. The compilation happens in the client.

2. Metadata is exchanged from SQL to the client and back to SQL.

3. A long compiling duration happens due to deserialization of metadata in memory cache.

In the Microsoft Dynamics AX 2012 R3 compiler, enhancements have been made from an architectural concept that makes the compiling process more productive and faster than in earlier versions.

Note

In the Microsoft Dynamics AX 2012 R3 compiler, the following processes happen:

  • The compilation happens on the AOS

  • Error logs are generated in each AOS

  • No metadata exchange

  • X++ execution time during the compilation has been reduced

  • More available memory and no cache

Note that you can compile X++ code to common intermediate language (CIL) used by .NET Framework to improve the performance.

X++ code is compiled to p-code and the last code is compiled to CIL by following this path: AOT | Add-ins | Incremental CIL generation from X++.

Depending on your process, the performance improvement can be between 0 and 30 percent. Therefore, you will have to test to know whether performance improves by running your process in CIL.

Debugger

The debugger is a standalone application and is not part of the Microsoft Dynamics AX shell. The debugger allows the debugging of X++ code in any of the following Dynamics AX components:

  • Microsoft Dynamics AX client (the Tools menu | Options | Development | Debug).

  • AOS. From AOS, navigate to the MS Dynamics AX server configuration utility | Start | Administrative Tools | Microsoft Dynamics AX 2012 Server Configuration | Create a new configuration. Select the Enable breakpoints to debug X++ code running on this server checkbox.

  • Business Connector. For enterprise portals, navigate to the MS Dynamics AX server configuration utility | Start | Administrative Tools | Microsoft Dynamics AX 2012 Configuration | Create a new configuration. Select the Enable global breakpoints to debug code running in the Business Connector or client checkbox.

For the debugger to start, a breakpoint must be hit when the X++ code is executed. You set breakpoints using the X++ code editor in the Dynamics AX development workspace. The debugger starts automatically when any component hits a breakpoint.

Note

To enable or disable a breakpoint, press Ctrl + F9.

To list all breakpoints, press Shift + F9.

To set or remove breakpoints, press F9.

Breakpoint tables are located in SysBreakpoints and SysBreakpointLists tables.

Projects

In AOT, you can use projects to group and structure elements according to your preference. A project is a powerful tool in the AOT because you can collect all the elements you need for a feature in one project. Projects can be opened from the AOT by clicking on the project icon in the toolbar.

When you create a new project, you should decide whether it should be shared among all developers or between private developers. You can use the Drag and Drop feature to move a project from shared to private or vice versa.

You can determine a start up project that opens automatically when Microsoft Dynamics AX is started by specifying a certain project in the options form.

The property sheet

Properties are the backbone of the metadata system; each property is a key and value pair. You can use the property sheet to inspect and modify properties of elements.

By default, the property sheet appears when opening the development workspace. It is automatically updated to show properties for any element selected in the AOT.

The property sheet contains two columns: the key and the value pairs for each property.

In the Categories tab on the property sheet, you will find a lot of information related to the selected element, for example, CreationDate, CreatedBy, CreationTime, ChangedBy, and so on:

Docking the property sheet on either side of the screen is very easy, and this can be done by right-clicking on the title bar.

Also, you will notice that there are elements that have time values and user information at the end of every property sheet, and the read-only properties appear in the gray label editor.

The label editor in Microsoft Dynamics AX 2012 is a text resource that is used throughout the whole product. It is a way to help you know more details about any element (the column header, the name of the form in the window, the help text in the status bar, captions on forms, and texts on Web forms).

You can use the label editor as a useful tool to help you when creating support service on Microsoft Dynamics AX or to know where an error message is produced, and this will give you more information related to the element selected.

Labels are localizable, and this means that they can be translated into most languages, because text resources are kept in a Unicode-based label file that must have a three letter identifier (for example, @SYS1234).

The structure of the label file is very simple:

@<Label File Identifier><Label ID><Label Text>

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can create new label files using the Label File Wizard, and you can access it directly from the Label Files node in the AOT or from the Tools menu | Wizards | Label File Wizard.

Note

When naming a newly created label, the three-letter ID that you will choose must be unique. You can use your company's initials as an ID:

The cross-reference tool

The concept of a cross-reference tool is very simple; if you have two elements (X and Z) and you want to know which one is in use by the other one, with cross-reference you can determine which elements are in use and which elements out of use.

These relationships between objects or elements are being recorded, so it is easy for you to track changes you or others made previously on all elements, so to keep yourself updated with this information, you must update the cross-reference tool regularly to ensure accuracy. This update will take several hours because it also compiles the entire AOT.

Note

To update the cross-reference tool, go to Tools menu | Cross-reference | Periodic | Update.

When the cross-reference tool is updating, it scans all metadata and X++ code.

To preview the whole list of cross-referenced elements, open the AOT, expand the SystemDocumentation node, and then click on Enums and xRefKind.

The Find tool

By pressing Ctrl + F from any node in the AOT, a Find window appears. It contains most of the useful tools to search for anything in Microsoft Dynamics AX application.

The Find tool contains multiple tabs such as Date, Advanced, Filter, and Properties.

For the Date tab, you can specify a range of dates for your search, such as the modified date and who they were modified by.

In the Advanced tab, you can specify more advanced settings for your search, such as the layer to search, the size range of elements, the type of element, and the tier on which the element is set to run.

On the Filter tab, you can write a more complex query by using X++ and type libraries.

The Properties tab appears when All nodes is selected in the Search list. You can specify a search range for any property. Leaving the range blank for a property is a powerful setting when you want to inspect properties; it matches all nodes, and the property value is added as a column in the results.

The results appear at the bottom of the dialog box as they are found.

The Find tool searches the selected node and related subnodes in the AOT, and if you want to search several nodes, you can mark the Use selection checkbox; by unmarking this feature, you will disable this feature.

The table browser tool

Table browser is just a standard form that uses IntelliMorph to view and edit data in tables. You can use this helpful tool in numerous scenarios, such as debugging, validating data, modifying, cleaning data, and so on.

The table browser tool is implemented in X++, and you can find it in the AOT under the name SysTableBrowser.

To open the table browser:

  1. Locate the table that you want to view in the AOT.

  2. Right-click on the table and then navigate to Add-Ins | Table browser. Alternatively, you can right-click on the table and select Open.

  3. The table browser displays data from all fields in the table.

In Microsoft Dynamics AX 2012 R3, the table browser tool can be used to run SQL statements by entering the SQL statement in the textbox and just clicking on the Execute button to run the SQL against the data source.

You can use the Autoreport field group to make it easy for you to find the values you are looking for in tables that have many fields.

The best practice tool

The best practice tool is embedded in the compiler, and its main function is to detect defects and risky code patterns in the X++ code. It is used when making customizations in the application and it is useful to decrease the time and cost that occurs when implementing the application or for any maintenance of the system.

It is the MorphX version of a static code analysis tool that allows any developer to run an analysis of his or her code and application model to ensure that it conforms to a set of predefined rules (400 rules) by displaying deviations from the best practice tool in the compiler output window.

Note

To turn off the best practices tool, go to Tools menu | Options | Development | Compiler and set the Diagnostic Level value below 4.

The majority of the 400 rules focus on errors and warnings, and the best practice tool allows you to suppress errors and warnings and identify the deviation as reviewed and accepted.

To identify a suppressed error or warning, place a line containing the following before the deviation:

//BP Deviation Documented.

The reverse engineering tool

Reverse engineering is a general process of analyzing a specific technology to know how it was designed or how it operates. One of the best known tools in the world is located in Microsoft Dynamics AX as UML.

UML is a general modeling language in the field of software engineering, which is designed to provide a standard way to visualize the design of the system.

In Microsoft Dynamics AX 2012, you can generate UML Visio models from your existing metadata or an entity relationship data model and see how they relate to each other in a visualization mode. You must have Visio 2007 or higher to use the reverse engineering tool.

To open this tool, from the Tools menu, select Reverse engineer; then select the model type as Visio UML Data model.

This tool deals with projects, so you will have to select either Private project, Shared project, or Perspective.

When you click on the OK button, all the elements in the selected project generate a Visio document that opens automatically, and any relationships between any elements will be easily visible to you.