• No results found

MorphX Environment

In document DAX Hand Book (Page 33-73)

The MorphX Development Suite is the integrated development environment (IDE) in Microsoft Dynamics AX 2009 used to develop and customize both the Windows interface and the Web interface.

An IDE integrates development functions such as designing, editing, compiling, and debugging within a common environment. With MorphX, common operations such as building or modifying forms, menus, and reports are done using drag-and-drop techniques with little or no coding.

Development environment features in Microsoft Dynamics AX:

 Microsoft Dynamics AX MorphX is an integrated development environment (IDE) for developing in Microsoft Dynamics AX.

 Visual Studio is an alternative development environment for web, report and managed code development.

 The Application Object Tree (AOT) provides a uniform and compact viewing repository.

 Drag-and-drop functionality is supported for many programming tasks.

 Projects help organize and track customized applications in Microsoft Dynamics AX.

Microsoft Dynamics AX Rich Client is the primary client to access Microsoft Dynamics AX functionality. Most forms displayed in the rich client are designed by using the MorphX development environment. Developers can access the developer tools through the MorphX IDE in the Microsoft Dynamics AX client or through Visual Studio Tools in Visual Studio.

The Microsoft Dynamics AX application is built of elements that are stored in the model store in the SQL Service database. For example, the following element types make up part of the application:

 Fields and Tables define data structure.

 Forms and Menus define how a user interacts with the application.

 Classes and Methods are code objects that define business logic.

The Application Object Tree (AOT) provides a visual representation of the elements that comprise the application.

Object-oriented design and Inheritance are key concepts that form the basis of the application.

Application Object Tree

The Application Object Tree (AOT) provides a visual representation of the elements that comprise the application.

A full definition of all the element types in Application Object Tree (AOT) can be found in the development training material and developer Help files. Some of the root element types include:

 Tables contain a group of associated fields. For example the VendTable contains fields relevant to Vendors. Fields on a table contain individual parts of data. An example is, AccountNum, one of the fields of VendTable contains the vendor account number. Fields on a table inherit properties from a base data type or an extended data types.

 Extended data types define a data type and extended properties of that base or another extended data type. There are various basic data types such as a string, integer, date, time and enum. For example, AccountNum is a string extended with properties including a length of 20 characters and has few other properties set.

 Base Enums are enumerated text data types. These are predefined text values that are referenced by an integer value in the database. For example, Gender is an enum that gives the user only two options (Male or Female) as to know gender of an employee.

 Classes contain code that is used in the application.

 Forms have the layout of all of the forms used throughout application. Forms are used to view data in the Microsoft Dynamics AX client.

 Visual Studio Projects display any development projects created in Visual Studio. Once we create a project in Visual Studio, it should be added to Application Object Tree to get into the AOT, or we don’t find that project in AOT.

 Menus define forms, reports and executable units of code that appear in the menu in the Microsoft Dynamics AX rich client.

Application Object Tree will be covered extensively in subsequent chapters in following text.

The following image shows how Microsoft Dynamics AX rich client and MorphX looks: [Please note that the image shown here is of Microsoft AX 2012]

In the above image you see, following are the component that can be discussed about:

 Breadcrumb Bar: The bar in which you are able to see the company selected [DAT], the module selected [Accounts payable]. This is used to navigate through the companies configured, modules [also called as verticals] available. This can also be called as Address bar.

 On the left side, we are able to see a pane, called as Navigation pane through which we can open the elements like forms/reports etc. which can be used by end users. This is used for navigation between different forms and reports and other elements in a module and you can also navigate between modules.

 You can also see File menu and few shortcuts which can be used to find help, about Microsoft Dynamics AX version and models information, to switch between Development and User workspace etc.

 The central part, which occupied most of the space, is called as content pane in which you will find the menu items which are used by end user to open the forms/reports. If you click on a particular menu item, you will be able to see that element on your screen.

 Finally, there is a status bar which will give you information about unread notifications, the company, currency information etc. You can also configure/customize this to display the items you need and hide items you don’t need.

The above image is only user workspace and developer workspace looks as shown in coming image:

Status Bar File Menu and

Shortcuts on right

Navigation Pane

The main difference between AX 2012 and AX 2009 regarding to the environments is, in AX 2009, there is only one workspace which is used by both developers and users. Whereas in AX 2012, there are 2 workspaces namely, User Workspace and Developer Workspace.

The following are the components we identify in the above figure:

 A menu bar and shortcut bar which are used to do the standard operations, in which we will discuss some of them in the following sections.

 The Application Object Tree (shortly AOT), in which you are able to see a tree structured nodes which are used for development of various components used throughout ERP.

 A properties window which displays the properties of the objects in AOT.

 Code editor, in which developers can write, edit, compile and execute the code. Code is written in an object oriented programming language called X++, which will be covered in coming sections.

 A compiler output window in which you can find errors/warnings etc. once you compile the code. The usage of these windows is covered in debugging section of this text.

 Finally, status bar will give you information about the environment like, the model, layer etc.

you are working on. You can customize these to hide or make visible as per your requirement always.

As we covered enough introduction stuff, it’s time to get into the basic development stuff. In this text, I’m starting from X++ programming rather than the regular approach to make developers feel

the environment and get hands on experience and make familiar to the environment which will help at later stage while developing applications. Those who like to see programming later can follow the AOT and get into the programming at later stage when they feel that they are familiar. I’d like to receive the feedback on the approach for better organizing the structure of the book in further editions.

Unit II

1. X++ Introduction

2. Object Oriented Programming in X++

3. Data Dictionary 4. Macros

5. Queries 6. Resources

X++ Introduction

X++ is the primary programming language used in the MorphX Development environment. The following are important features of X++:

 X++ is an Object Oriented Programming Language very similar to Java and C#. Due to this, programmers feel easiness and very convenient working with the language.

 Complex business logic for accounting and business management systems can be built very easily with the help of many integrated SQL commands.

 Programmers can access the existing system classes that can be used to extend the functionality of the application.

Characteristics of X++:

Reliable: X++ provides extensive compile-time checking, followed by a second level of run-time checking. Language features guide programmers toward reliable programming habits. The memory management model is simple; objects are created by using a "new"

operator and there is automatic garbage collection.

Interpreted and Dynamic: Benefit from faster development cycles - prototyping, experimentation, and rapid development, versus the traditional compile, link, and test cycles.

Interoperable: Components in Microsoft Dynamics AX are seamlessly available to any application supporting .NET, and conversely X++ is able to consume external managed code and COM objects.

Case Insensitive: X++ is case insensitive, but, some naming conventions are followed for better understanding of code.

No pointer arithmetic: X++ doesn’t support pointers, which eliminates complexity in the language.

Development Tools:

All elements that comprise the Microsoft Dynamics AX application (classes, forms, tables, and more) are organized in the Application Object Tree (AOT). This is a central, organized index to all application elements, displayed in a graphical tree view.

Microsoft Dynamics AX customizations are developed by modifying one or more elements from the AOT. These elements are usually assembled in a project, or, in other words, a container for elements that implement an application in Microsoft Dynamics AX. Projects help manage development efforts by organizing units of functionality.

As developers create new projects or modify existing projects, they use a series of development tools. These tools include the following:

 X++ Editor

 X++ Compiler

 X++ Debugger

 Visual Studio

 Visual Studio Debugger

All the above tools except Visual Studio are accessible from Microsoft Dynamics AX Development Workspace. To open the development workspace, press Ctrl + Shift + W from regular user workspace or simply add –development to the command line parameters to start development environment using AX client shortcut.

The above described tools are discussed as follows.

X++ Editor

This is the place where code is written, compiled and executed. Most AOT nodes [methods]

which have code can be opened with a double click which will open the below editor and show the lines of code. This editor can also be started by selecting View Code in the right click context menu. The following image shows the look and feel of X++ code editor:

The above window (image) consists of two panes:

 One for displaying the current methods or jobs.

 The right pane displays the X++ code.

There are many toolbars buttons available in heading of X++ editor window. These are used for regular operations like New, Save, Compile, Run etc. You can find the shortcuts for these in Shortcuts section of appendixes. To find the use of specific button, point at the button using your mouse pointer, you will find the use of the button.

X++ code editor uses following color codes for better understandability of developer:

Color Code type

Blue Reserved words

Green Comments

Dark Red Strings

Bright Red Numbers

Purple Labels

Black Everything else

As we know the basics of X++ code editor, it is time to start the programming in X++.

My First X++ Program

static void job1 (Args _args) {

info(“Hello World!”);

}

The above program displays Hello World! in a window similar to a popup. This window is called as infolog and is used most frequently to display the output on the screen.

The following points can be noted from the above program:

Every block of program should be enclosed in { and }.

Every statement in X++ program should end with ;

Now, let’s try to understand where to write the above program and how to execute that, which covers what is job, which is used in the above program.

Jobs

A job is a stand-alone block of code in Microsoft Dynamics AX that can be run from the X++

editor. Jobs are used basically for testing code during development and running batch processes within Microsoft Dynamics AX that affect large amounts of data.

This section will explain you about using the Jobs for writing code snippets, executing them directly from X++ editor about compiler and basics of X++ compiler. Most of the code for any requirement is written in classes, methods, tables and/or forms. As said above, jobs are useful for testing code before using them directly in methods or classes. Following is the code when you create a Job:

static void Job1(Args _args) {

}

Note: You can always change the name of Job, which is always advisable to give a better name as per naming conventions and to remember the purpose of the Job.

To create a new Job, right click on Jobs node in AOT, select New Job, You will see the X++ editor opening with the newly created job. Rename this job to MyFirstJob. We will write info to display some output:

static void MyFirstJob(Args _args) {

info(“Hello World!”);

}

The above program display a window called as infolog with a line “Hello World!”. To execute the above code snippet, first compile the Job, later execute the job. You can find detailed step by step approach for compilation, debugging and executing in Appendixes. Simply, F7 is used to compile and F5 is used to execute the job. If you get any errors, please check the following frequent errors which an inexperienced developer may encounter:

Missed semicolon (;) after end of statement info().

If you are working on AX 2009, you have to give a semicolon (;) before info() as the declaration section should be terminated by a semicolon (;) in AX 2009, which is not required in AX 2012.

Missed ( or ) or { or } or “ or misspelled keywords.

Please check for the above errors, resolve them, re compile and execute. You should see the output as expected with an infolog.

Finally, Args is used to pass arguments from caller. We will discuss about Args more clearly with samples in further sections of this book.

Comments:

Comments are used to describe about a line of code or the program. There are multiple types of commenting in X++, used for different purposes. Though it is not mandatory, it is advisable to comment consistently where ever applicable for the following:

 What does the code does and how the parameters are used.

 Who made the change and why the change was made for future use.

Note the following points before comments are used:

 Comments can be directly inserted into the lines of code at any place and any point of time.

 Comments are ignored by the compiler i.e. comments are not compiled either they have executable statements or plain English statement. So, if a code is not required (while testing or for time being), you can comment those lines of code.

 When you comment, comments will turn the code into green in the editor. This makes you identify the commented lines differently.

Some commenting styles are as follows:

 Single line commenting, done using "//". This will comment only one line at time.

// This is a single line comment.

 To comment multiple lines, we use block comments "/* */". “/*” will start the comment and will comment line(s) until you end with “*/”. Please note, if you forget the end, you may encounter an error.

/*This is a block comment.

This can have more than one line. */

 To do comments "TODO." To do comments appear in the compiler's

Tasks tab page. These are used to indicate that you have to do some task or add some lines of code.

 XML documentation comments. These are used to write notes about a method, the parameters used etc., precisely the purpose of the element. An example is as follows:

///<summary>

///Comment using XML tags to distinguish sections.

///</summary>

These XML documentation comments are used to build XML documents that will have the developer documentation, which can be used to display help in X++ editor further.

As we became familiar using the jobs, how to write a job, compile that, execute that, it’s time to get into further step, declaration of variables, following with advanced stuff as follows.

Variable, a memory block used to store the data which is used in program to get the expected result. Variable holds the data when the program executes. To declare a variable, we need to identify the type of data that is stored in the variable. For example, age of a person is an integer value whereas, the amount that should be collected from customer or to be paid to vendor is a real value. Once the type is identified, declare a variable following the naming conventions. We will see how to declare, use the variables in this section. Following is a sample program which demonstrates how to declare variables:

static void Declaring Variables(Args _args) {

int age; //This declare a variable named age, which can be used to store integer value.

}

In the above program, we have declared a variable named age. This variable can store numeric digits, positive and negative but, will not accept characters. Now, let’s assign value to this variable, an = is used to do that as follows:

age = 28;

The above statement will assign the value 28 to age, when you try to retrieve value of age, 28 will be returned. The following chart describes about the available data types in X++ and the values that can be stored.

Data Type Description Keyword Example

Declaration String A string is a set of characters. X++

supports following types of strings:

aligned [left or right], fixed length or variable length. The length of a string can be maximum of 999 characters.

Null value is represented by empty string.

Str CustomerName

Integer An integer, also named a natural digit, is a number without decimal point. Null value is represented by 0.

Int 1090

Real Real values, also called decimals, are digits with a decimal point. Null value

Real 3.14

is represented by 0.0.

Date The date type contains day, month, and year.

Date 12/22/2012

UTCDateTime This type contains year, month, day, hour, minute and second. Null value is represented by 1900-01-01.

utcDateTime 12/22/2012 04:00:59 am

Enum Enum values are represented by

integers internally in database though we are able to see as strings in frontend. The first literal has the number 0, the next number 1 and so on. You can use enums as integers in expressions. Element value with 0 is assumed as null value.

Must be declared as a BaseEnum first

Gender

Boolean Booleans can only contain the values false and true. The values false and true are predefined in X++ and recognized by the compiler.

Boolean TRUE

Time This type contains hours, minutes, and seconds. To declare a time, use the system type timeOfDay. Null value is represented by 00:00:00.

timeOfDay 04:00:59

GUID Global Unique Identifier (GUID) is a reference number which is unique in any context.

Guid

{5D2503A0-4S80- 55D3-0P9C-2908H82C3804}

Int64 A large integer, represented by 64 bits.

int64 11234567890

The chart above shows the types, the values that can be stored by variables of that type and a sample declaration/value that is stored when we use the type. The above types are called as primitive types or basic types which are used to store basic values. Note that, each variable can store only one value at a time. If you assign one more value, previous value will be replaced with newly assigned value and if you try to store multiple values, you will get error in return.

Syntax for declaring a variable is as follows:

<dataType><variableIdentifierName>;

Following are few examples for the above shown types:

Following are few examples for the above shown types:

In document DAX Hand Book (Page 33-73)

Related documents