Microsoft Dynamics AX 2012 :Understanding Related Field and Fixed Field relation on Ax Tables

Hi All,

Field Fixed relation

Suppose we have three tables

1) Player Table  2) Footballer 3) Cricketer

Player Table with following fields

  • PlayerName (string)
  • PlayerBenefits(string)
  • Player Type(Enum  contains Cricketer and Footballer)

FootBaller Table with following fields

  • Category (Enum contain A,B,C)
  • FootBallerCode(string)
  • Salary (real)

Cricketer Table with following fields

  • Category (Enum contain A,B,C)
  • CricCode(string)
  • Salary (real)

Here is how they all created:

Tables.jpg

Now populate some data in Footballer and Cricketer table

Second

Third

Scenario

Now For Player Table

If we select  ‘Player Type’ = Footballer then on Player Benefits field on the Player table ,lookup should be open showing the records of footballer and similiary with the case of cricketer,for this to achieve we can use the relation called ‘Fixed field’ to accomplish this.

So go to the Player table under realtion node and create a field fixed relation and here it is what I have done

Four

  • It says that  PlayterTable.PlayerType ==0(since Player Type(Enum  contains Cricketer which has a value in database equal ‘1’ and Footballer has ‘0’) you can verify by navigating to base enum and view its properties,
  • So it mean if the PlayerTable.PlayerType == Footballer then

PlayerTable.PlayerBenefits == Footballer.FootballerCode(shows the lookup of Footballer data)

And similar is the case with Cricketer see below now

Fifith

So now lets insert some data on Player table

Sixth

And

7th

Related Field Fixed

Note: below is copied from external resource

This relation restricts the records selected in the related table. Only records that meet the condition are selected.
The condition is ANDed with your relation.

Secondary table filtration can be done on the basis of relation set using related field fixed.

Example:
Primary Table:tableA(col1,col2,col3)
Secondry Table:tableB(col4,col5,col6)-col5 is an enum & can contain values 0,1,2.

tableB has 6 records as following

col4      col5     col6
1)      –           0          –
2)      –           1          –
3)      –           2          –
4)      –           1          –
5)      –           0          –
6)      –           1          –

We can set the related field fixed relation in tableA as
1==tableB.col5

It will give the lookup of 3 records of tableB i.e. 2,4 & 6th records.

Based on similar understanding I have implemented following

8th

 So we have four records in InventoryPhoneTable

9th

But when we click the look up,only showing two record

1oth

Please let me know for any concerns

Microsoft Dynamics AX 2012 :Table Inheritance Part 1

Hi All

In Microsoft Dynamics AX 2012, tables can inherit, or extend, from the tables that are situated above them in a hierarchy. A base table contains fields that are common to all tables that derive from it. A derived table inherits these fields, but also contains fields that are unique to its purpose. Each table contains the Support Inheritance and Extends properties, which can be used to control table inheritance.

First we need understand that when we need to apply this inheritance methodology to tables. First we need to identify the Parent table and its siblings like

DataModel

Here ‘Basic Info’ is the Parent table containing fields that are required for its child table i.e. CompnayTable and EmpTable. And these tables have their own fields as well.Now to design a Inheritance pattern we need to consider following important things:

 

  • We can only apply inheritance on regular tables not on Temp or Memory tables
  • A type discriminator field must be defined on any table inheritance hierarchy created in the AOT. The field must be defined as an int64 type on the root table, with the name of the field set to InstanceRelationType.
  • The InstanceRelationType field of the root table is read-only and stores the TableIDs of record instances; it is populated automatically by Microsoft Dynamics AX 2012.
  • Also we can only set the table properties for the table inheritance only when there are no fields in the table.
  • If these requirements are not met, a compilation error will occur when the table inheritance hierarchy is compiled.

Let create parent Table ‘BasicInfo’

BasicInfo

Setting its SuppourtInheritance Prpoerty to Yes

SupportInhheritane

When you save and compile,it will give following error

ComipleError

For this we need to create a discriminator; name ‘InstanceRelationType’ and of type Int64.Now I have created a field including discriminator

InstanceRelationTYpe

Finally I have set another table property ‘InstanceRelationType’ to ‘InstanceRelationType’  field

InstanceRelationTYpeProperty.jpg

And when I compiled, the error is gone now.

Now we have to create Two child tables

EmpTable:

First I have set the ‘SupportInheritance Property to Yes.

SupportInheritance

Now for the child table to have the parent we need to set the ‘Extends’ property of child table to parent table value like

ExtendsProperty

And finally added all fields.

EmpTable

 

CompanyTable:

Same as what already we have done for EmpTable

Now when I compile it still give the two errors i.e.

TwoCompilerErrors

Basically these errors indicates that the automatic relation that have been created in the child table,have the same relation name and so it is showing duplicate so for this I have changed the name See below screen shot

ScreenShot (see below)

 FinalScreenShot

And that’s it we have created Parent-child hierarchy table .

Finally, we need to also set the ‘Abstract’ property of the parent table to ‘Yes’ and for this we need to understand below.

Abstract versus concrete tables:

Tables in a table inheritance hierarchy can be defined as either abstract or concrete, depending on whether the table property Abstract is set to Yes or No. Records can only be created for concrete table types. Any attempt to create a record and insert it in an abstract table will result in a run-time error. The position of the table in the inheritance hierarchy does not restrict its ability to be defined as abstract.

Microsoft Dynamics AX 2012 :Use of static construct() and static new() method of a class

Hi All

Use of static construct() method and static new() method of a class

Static Construct():

This method returns an instance of the class. It is a best practice to have a construct method in your class. This method should always be static but can be public or private depending upon the use. When calling a class from another class or job construct method can be used for this

Example:

To give you an example, let assume that we have a class ‘AsimConstructClass’ and have a variable ‘Name’ having a parmName method to be set or get

pic2

Here I have create a construct method from template, which is returning the instance

pic3

I have also create a run method for my logic in a class

pic4

Now, finally I have created a job and in this I will get the instance of the class and call the run method in a single call

pic5

Static New():

Basically new method is the default constructor of a class invoke when user uses ‘new’ keyword. Mostly it is protected like.

pic6

But in some cases we can create our own static new method like

The above example for construct method, shows an infolog with the name ‘Asim’ which is a hardcoded value in a class, So now what if  a user wants to send some input from a another class or job. In order to do this we can create your own individually named static new… methods with different parameter profiles and make it public static

Here newName takes a parameter,

pic7

Also in the newName code, it is initializing the instance by calling the construct() method which should be private in this case ,so I made it private

pic8

And now in the job I did this

pic9

Finally on running it will show

pic10

Microsoft Dynamics AX 2012:Example of Client Server Methods in AX 2012

Hi,All

Client/Server method modifier and ‘Run On’ property of object

Client /Server

Basically these are the method modifiers use to minimized the load/traffic between client and server. These modifiers can only be used for static methods of class and table static methods. These can’t be use for instance methods because these method will be run on where the class instance method created. Also we can’t’ use these modifiers for  table methods insert, doInsert, update, doUpdate, delete, and doDelete on the Server (where the data source is).

Since we have Client tier (AX Client) and Server tier (AOS), so if we want to execute our method on client then we can set the method modifier to ‘client’ and if we want to execute the method on server than we can set the modifier to ‘server’.Also if don’t set and modifier to the method then method will be run based on the ‘RunOn’ property of the class.If the RunOn property of the class is set to ‘Called From’ then method can either be executed on client or server.

image001

// Sets the RunOn property to Client.
client static boolean myMethod()
{
    // ToDo Insert code here.
}

Above method will be run on AX client

 

// Sets the RunOn property to Server.
server static boolean myMethod()
{
    // ToDo Insert code here.
}
Above method will be run on AOS 
But we can also do this(see below) 
which apparently make the property of the method to ‘Called from’

// Sets the RunOn property to Called from.

client server static boolean myMethod()

{

// ToDo Insert code here.

}

Some Best Practices for Client/Server Modifier:

http://msdn.microsoft.com/en-us/library/aa672948.aspx

Example1(Client modifier):

We have a table called ‘JournalizingDefinition’ which has a static method ‘lookupRefCtrlJournalizingDefByModule’ which has a ‘Client’ modifier declare. Now this method will always we be used for a form lookup field on a ‘Transaction Posting Definition’ form

imapge2

Transaction Posting Definition form

image3.jp

Now on a lookup field of the form this method is being used several times for different module(see below).So basically it means that this method will never be used on Server side that’s why it is set to Client(AX Client)

image5

Example 2 (Server modifier):

We have a class ‘LedgerJournalPost’ which has a method called ‘Post’ which is apparently used when we try to ‘Post’ a journal.

image6

So it mean that this method will always be called on Server AOS for posting purposes, please let me know for any concern

also see

http://axdaily.blogspot.com/2010/02/moving-code-execution-from-client-to.html

Microsoft Dynamics AX 2012 :Maps in AOT

Hi All today i am covering a small topic which is Maps in AOT

Maps are nothing just an element/object the makes possible to link/associate map fields with fields(same type with different names) in different tables like, I have create a MAP with field (AccountNum) and Same field exist in CustTable and also in VendTable,so I can associate field in CustTable and in VendTable with Maps, so basically  Maps enables to access the fields with different name in different tables.

EXAMPLE:

I have created a Map by navigating to AOT>Data Dictionary>Maps and right click and new and gave it name ‘MapTest’

map1

I have created 4 fields in under Fields node in Map (drag and drop from EDT)

map2

Now the next thing I need to do is to associate the fields in map with the fields in different tables, let say I am taking two tables (CustTable and VendTable).

map3

Notice that above, four fields that I have created in Maps also exist in CustTable as well as VendTable with different names.

To associate fields, go to Mapping node, right click it and click New mapping, and enter the table that you want to associate in Mapping Table field. Like

map4

And the associate fields with fields in MAP

map5

Now I have created a method called printInfo under method node in Maps, which print the value of the map field AccNumber.

public void printInfo()

{

info(strFmt(“Map : AccountNum :%1″,this.AccNumber));

}

Similiarly I have create same methods under method nodes of CustTable and VendTable which are printing their respective AccountNumber fields

map7 map8

Now finally I have created a job see below I  am not describing every line as I have added comments above the line.

map9

When I run this job see what happens

map10

Microsoft Dynamics AX 2012:Example of Cascade,Restricted and Cascade + Restricted (Delete action property for a table relation)

Hi, Hope you guys are fine!.

Use of Cascade, Restricted and Cascade +Restricted (Delete action property for a table)

image018

 

Example of Cascade

Suppose we have two tables  (Customer & Order) and the relation is of One-To-Many i.e. Customer can have many orders

So on a parent table i.e.(Customer) if I set a delete action property to “CASCADE” for Order table. Then If I go and delete the record from a Customer table. It will also delete all the related records in Order table automatically

Example of Restricted

Suppose we have two tables  (Customer & Order) and the relation is of One-To-Many i.e Customer can have many orders

So on a parent table i.e.(Customer) if I set a delete action property to “RESTRICTED” for Order table. Then If I go and delete the record from a Customer table. It will first check the record in the child table and if exist that warning prompt saying that first we need to delete a record from child table.

Example of Cascade + Restricted

Suppose we have three tables  (Person ,Customer & Order) Now Person is a parent of Customer table, and Customer is a parent of Order table having (One-To-Many) relations

If I set a Delete action property on Person table to “CASCADE” for customer table  and If I set a  Delete Action property on a CUSTOMER table for Order table to “CASCADE +RESTRICTED”.

So if I delete a record from Customer table then It will first check the record in the child table(order table) and if exist that warning prompt saying that first we need to delete a record from child table.

But if I delete a record from Person table it will automatically delete a record in Customer table and all records related to customer table in Order table would also be deleted.