Form development from Basic level in Microsoft Dynamics AX 2012 R3

Contents

Overview
Create New Project
Define Database
Extended Datatype
Create Tables
Field Group
Indexing
Create Form- State Master
Create Form- City Master
Create Number sequences
Create common class to generate the city code using number sequence


1. Overview

Consider a scenario where we are going to build two forms. state master and city master in dynamics AX 2012.
For this post, we are cover following points to develop this small add-on.

AX Project.
City and state master table.
Entry forms for city and state master.
Create the common class to generate the city code using number sequence.

AX Project: 

AX Project for collecting Ax artifacts in single location. 

When we create any Ax object they have to create under certain node. For example, tables, forms, Classes, menu all stored in their respected node.

In Dynamics Ax we can create a Project which is not more the logical grouping of all Ax artifacts. 

In these project, we create object groups and then placed our required object either drag and drop from AOT or create them here. 

Advantages of Projects are
Logical grouping, it’s easier to locate required artifacts one location. 
When we export project as Xpo, all objects are exported as single XPO. 
We can export whole project into model, all object in project moved from one model to other model in single steps. 

2. Create New Project

Let’s make a new project. From top menu Click on View >> Project









Following Screen will open.










Right click on Shared folder and create a Project and renamed it to dev_MasterForms.












Click on Project and open it. Right click on it new >> Group to create new groups.









For example, we create Form group and set it Name and Project Group type to forms. Similarly create other groups.

3. Define Database

Now we create tables for city master and state master forms.
table structure look like
dev_StateMaster table.


Column
Extended data Type (EDT)
Primitive Data Type
Key
StateCode
dev_StateCode
Str2
Primary Key.
StateName
Description

Not allow duplicate.

dev_CityMaster table.


Column
Extended data Type (EDT)
Primitive Data Type
Key
CityCode
dev_CityCode
Str10

CityName
Description


StateCode
dev_StateCode

dev_StateMaster (Foreign Key)


3.1. Extended Datatype

First we create extended data types for both the tables. First one is dev_StateCode EDT.









When you save any Extended Data Type, Ax ask for Synchronize database cancel it when all extended data Types created let it complete.












Similarly create dev_CityCode EDT.


3.2. Create Tables

Now create a click on tables group and right click and create a new table
Rename it to “dev_StateMaster”.










Now create a new field with name “StateCode” with string type and set its extended data types to “dev_StateCode”.














Similarly create other fields in table.

3.3. Field Group

Now expand field Groups node in Table and Create a new Field group with Name “Overview”. Drag both the fields to Overview group.

3.4. Indexing

Now want to make the StateCode as unique and make it primary key. For this right click and create unique index on it.












Similarly create StateName as unique. For this right click and create unique index on it.

Similarly create dev_CityMaster table.


4. Create Form- State Master

Now we start development of forms. First form we will create for State Master. For this open AOT and right click on Form Node and click on Form and rename it as “dev_StateMaster”.




Expand dev_StateMaster form and Right click on data source node to new Data source. Update name of name and Table name as dev_StateMaster and set its Table properties to “dev_StateMaster” and also set “InsertIfEmpty” and “InsertAtEnd” to No.











Now, set caption property of Design as “State Master”.

Now create Add action pane of two buttons for create and delete the state master records at top of form.

Now Set Action pane’s style Property as “Strip” and expand designs and add new action tab, inside button group add two command buttons. Rename them into “btnCreate” and “btnDelete”. And from property window set their command to new, and delete.
































As display in below screen, Right click on design node and add gird.

Set grid properties as below.
Name: dev_GrdMain
Data Source: dev_StateMaster
DataGroup: overview
Width: Column width
Save the form and right click on form open it. The form will look like similar.












Similarly, we create city master form as follow. 

5. Create Form- City Master

Right click on forms node and select form and rename its name property as “dev_CityMaster”.














Now Right click on data source node to new Data source. Update name of name and Table name as dev_CityMaster and set its Table properties to “dev_CityMaster” and also set “InsertIfEmpty” and “InsertAtEnd” to No.

Now create Add action pane of two buttons for create and delete the state master records at top of form and Set Action pane’s style Property as “Strip” and expand designs and add new action tab, inside button group add two command buttons. Rename them into “btnCreate” and “btnDelete”. And from property window set their command to new, and delete.
As display in below screen, Right click on design node and add gird.














Set grid properties as below.
Name: dev_GrdMain
Data Source: dev_CityMaster
DataGroup: overview
Width: Column width
Save the form and right click on form open it. The form will look like similar.












6. Create Number sequences

Now it’s time to create number sequence to generate city code. Before creating number sequence, I hope you have some basic idea about Number sequence in AX. If you have not, I will give you some small description as below.
Number sequences in Microsoft Dynamics AX are used to generate readable, unique identifiers for master data records and transaction records that require them. A master data or transaction record that requires an identifier is referred to as a reference. Before you can create new records for a reference, you must set up a number sequence and associate it with the reference. 
We can create new number sequence from below menu path.
Organization administration >> Common >> Number Sequence >> Number Sequence.












Now click on number sequence button as display below.








After clicked on Number Sequence button following form will open.














Now set Number sequence code as “CityCode” and name as “City Code for City Master Form”.

Now set its property as display below.




















7. Create common class to generate the city code using number sequence

Now create common class to generate the city code using number sequence on create button click. Create new group and rename its name as “Classes” as display below.

Right click on the class node to add to new class and rename it as “dev_GenerateNumberSeq”.












Create one method inside this class to generate next number sequence. So right click on class node and select New >> Method and rename it as “GenerateNextNumberSeq”.












Now write a code to generate the next number sequence.





















Now we have to call this class’s method into dev_CityMaster table’s “initValue” method so whenever new record in city master table is created, new number sequence for city code is generated. So first set dev_CityMaster table’s filed “CityCode” to read only.










































Now open the city master form and check the code is working properly or not.



Previous
Next Post »