Thursday, August 27, 2015

How to: Use and Override Methods in Dynamics AX

Today I will discuss about the usage of methods in Dynamics AX. Since we have already discussed that in dynamics ax, we can override the methods at form and DATASOURCE level.

Now we have to understand that where and why we would need methods overriding? Let's go along with the same scenario of Student Course Enrollment. What if the user wants to see only active students in the Student Course Enrollment form. Obviously first thing we have to do is to add an active field in the student table and then we will have to filter the records of Student showing only the active students in the Students Course Enrollment Form.

We can do this by overriding the init() method at DATASOURCE level and add only a single line of code as given bellow where are adding the range in the query of the Student DATASOURCE after the super call in the init method.

this.query().dataSourceTable(tableNum(Student)).addRange(fieldNum(Student, StudentActive)).value(SysQuery::value(NoYes::No));


You can right-click and select "Personlize" on the form to check the ranges applied on the form as shown bellow.


We have init method available at FORM level as well as at DATASOURCE level. When we will override the init() method both at FORM and DATASOURCE level, init method of datasource level will be invoked at first. In our next few posts we will explore about the methods in detail. I hope you enjoy learning AX. Thanks for reading this post!




Friday, August 21, 2015

How to: Create a Simple Data Entry Form in Dynamics AX

I hope you had a good understanding of table relations and delete actions in my previous two posts.
Today I will give you an example of creating a simple data entry forms in dynamics ax for the student table.
After you create a table for student, you can use this table a DATASOURCE of Student form as shown bellow.



To have a better understanding I will also recommend you to go through this MSDN post as well.  As you can see we have five nodes bellow the forms. Methods, Data Sources, Parts, Designs and Permissions.

We can have many methods to override at form level and data source level and at individual fields level of the datasource. I would not be able to describe about the methods in this post but hopefully I will describe few methods and their sequence in any of my next coming post.


To add the DATASOURCE you can do by dragging the Student table to the “Data sources “node of the form or by right click and add the table.
Now, the DATASOURCE has been added, its time to design the form. Expand the Designs node, and right click the design to add controls, you will have following list of controls.

In AX 6.0 we have a control Action pane, you can use the Action pane as an "Action pane strip" by setting the style property of  "Action pane" as "strip". On that you can add buttons and its looks like the following,

I have kept this as simple as I can, however, this can be more beautiful by setting its properties.

The controls I am adding in our case are, Action pane strip with command button "New" and "Delete Record", Two tab pages "Overview" which contains grid and "General" which contains fields.

On the grid you can drag fields from DATASOURCE node of the form. Same for other controls, you can drag fields from DATASOURCE to any group control or tab page.

After all this you can open the form, and you can add or remove records. The form will look like this.


In my next coming posts, I will be explaining about the FORMS and DATASOURCE important methods and their sequence and when and why we use them. Keep following my posts and share your feedback as well. 

Thursday, August 20, 2015

Delete Actions in Dynamics AX 2012

Hope you had a good understanding about table relations through my previous post. Today I will be explaining about the delete actions. I will be going along with the same scenario of Student Course Enrollment. There are three tables Student, Course and StudentCourseEnrollment.
Each of the record in table StudentCourseEnrollment will be child of both Student and Course. Obviously, when a student in enrolled in a course, his record will be present in the StudentCourseEnrollment table. In other words StudentCourseEnrollment table is related to table Student.What if someone deletes the Student whose referrence is in StudentCourseEnrollment table? That's where delete action plays their part in Dynamics AX.

In Dynamics AX 2012, We can define four delete actions on Student table. None, Cascade, Restricted and Cascade+Restricted. I am going to explain all of the four delete actions here.













  • None: We would never like to keep the Delete Action None for the Student table because None means No action will take place on related records in the StudentEnrollment when you delete a record in the Student table.
  • Cascade: All records in StudentCourseEnrollment table related to the record being deleted in Student table will also be deleted.  
  • Restricted: The user will get a warning saying that the record in the Student table cannot be deleted because transactions exist in table Student Course Enrollment table. The user will be unable to delete the record in Student table if one or more related records exist in the Student Course Enrollment table.
  •  Cascade + Restricted: The delete action performs a restricted, if the record of the table will be deleted directly and peforms a cascade, if the record of the table will be deleted through a cascade delete action of another table. Let's say for example we have a student table which is also the child table of Department table. What if we have defined Cascade delete action in Department table for Student table. All the related records of the Student will be deleted and provided if we have defined "Cascade+Restricted" in the Student table for Student Course Enrollment table then all the data in course enrollment table will also be deleted. However, it will behave as Restricted delete action if there is no any other table where we have defined Cascade delete action for Student table.














Hope this scenario based explanation clears your concepts regarding Delete Actions.

Wednesday, August 19, 2015

Understanding relations in tables Dynamics AX 2012

Today I am going to explain the relations between tables by implementing a real time simple scenario.  Assume we have a student who is enrolled in a course. We want to keep the track record of the students who are enrolled in one or many courses. We would require two tables one for Student and other one for Course. Multiple students can be enrolled for the one course and one course can be taught to multiple student thus relationship exists between Student and Course is "many-to-many".  Therefore, we are going to add one more table naming it "StudentCourseEnrollment". Given bellow would be the ERD.

In order to implement this scenario in Dynamics AX 2012. We would first need to create three tables Student, StudentCourse and StudentCourseEnrollment.

While creating StudentCourseEnrollment, we have to add the relations of both Student and Course table,

  • Now while referring to MSDN post where there is detail description of properties of table relations. Here we would require to mark "Validate = Yes" because we would never like any body to play with data ignoring the relationship of the records. For example, we would not like some one to delete the data in Student (parent) table whose reference is in the StudentCourseEnrollment (child) Table. However, It also depends on the delete action we are going to define on the parent table. In other words, marking Validate yes will always take care of relationships and perform the validations accordingly.
  • I choose the option "ExactlyOne" for RelatedTableCardinality property because we cannot allow a null value in any of the records for the Student field of StudentCourseEnrollment table.
  • It is not necessary that every Student or Course record must exist in the StudentCourseEnrollment table, there can be multiple records related to single record of the student or course or zero, keeping this thing in mind, I am going to set the Cardinality property of the relation to "ZeroMore".
  • Now there is property named relationship type. We have six options which one would be best suited for our scenario.  Should I choose "Composition" here? since if we are going to delete a student record, all his course enrollment should be erased from Course Enrollment and same goes for Course. but wait since we can add delete action to enforce the relationship between Student and StudentCourseEnrollment table so why not choose  "Aggregation" here. I would also need your input on this as well.



After we set all important properties for relation we defined, click new and see there are four options (Normal, Field Fixed, Related field fixed and Foreign Key).









To gain better understanding for all of the four options, again check the MSDN. In my case I have selected Foreign key => Primary Key as we have normally been doing in Sql Server.

I have tried a lot to make this post brief and useful, I would explain the delete actions related to this particular scenario in my next post. Have good day!




Tuesday, August 4, 2015

How to get the customization done for a particular layer in dynamics ax 2012

Sometimes you would like to know about all the customization done so far in the development layer you are working on. That would really be great thing to have all the customization of development layer in single project. How quickly we can do this.


  1. Type Clt+Shift+P, you would see all the list of available Private and Shared projects.
  2. Right click and select New Project, it would create a new project by default with the name Project1.




















3. Next thing you need to do is open project you have created select the project filter. In dialog of project filter select the option of AOT in Groupings. Click button select for the criteria and choose the usr layer.


Here we can see the project which includes all the customization done on usr layer.


You can give any name to the project by renaming. Hope this would be useful post for you.

How to make unique field validation in dynamics ax form

If you need to make a form field unique, what you would need to do is to add a unique index to the table that is associated with DATASOURCE in the dynamics ax form. Here for example, I have student department and what I require is to make the student department's id unique.

1. My first step would to create an index in Indexes section of StudentDepartment table and then I would simply drap and drop StdDepartmentId field of of the table to that particular index.


2. Next thing I am going to do is to mark the AllowDuplicates property of that index to No.



Now when I am going to enter the duplicate department id, I am unable to see any record duplication error which I was expecting. What basically the issue here is to make a field unique, I would have to mark that particular filed mandatory too. So I would also perform one more step here.

3. Go to field section of the StudentDepartment table. Check the properties of StdDepartmentId and mark the "Mandatory" property to "Yes".

Now when I would try to enter a duplicate record, I would be able to see this error message.



Some times you are stuck at very small things in AX, so make sure you are doing all important things.