Monday, December 14, 2015

Debugging RDP class in AX SSRS Reports

I was trying to debug RDP class yesterday but I tried all the steps a provided and listed on MSDN with no luck. Eventually what I changed was to replace SrsReportDataProviderBase with SrsReportDataProviderPreProcess after the extends keyword it gave me the right result but there is still a limitation for this workaround that we cannot view the report. Hope this small blog post can save your day as well. There are still more steps we can follow to view the report as provided in this post.

Monday, November 2, 2015

How to fetch number of records in datasource in Dynamics AX

I am going to share through post that sometimes we need to retrieve the number of records in a particular datasource. Let's say we have two datasources in a form named Student and StudentCourseEnrollment.

I simply need to fetch the number of records in Student Datasource in the init event of the the form. I would require following peace of code for that.


public void init()
{
    QueryRun queryRun;

    super();

    queryRun = new QueryRun(Student_ds.query());


    info(strfmt("Total Records in Student Datasource %1",SysQuery::countTotal(queryRun)));

}

Further you can refer this post to retrieve the rows from the temporary data source as well.

Tuesday, September 29, 2015

Lookup by referrence field

Guys! In AX 2012, we could add the lookup in the form by reference field. For that It is necessary to understand the relations of tables. As we know relations between tables are used to associate rows in one table to rows in another table. In AX relationship between tables are defined within the MS Dynamics AX application and not at the physical database level. There are different sorts of relations. To get more detail visit the MSDN about How to Add a relation to a Table.
Lets say we have different categories of Items for storing in the inventory. I want to see specific category of items to be displayed in my lookup on inventory receiving form.
Start with adding relation in the inventory receiving table with items table. You can modify the relation according to your need. For showing the fruit category I have used related field fixed relation too.

There must be field group defined in Items table


Now add the reference group as new control in the grid container of the form and set the DataSource, ReferenceField and ReplacementGroupField Properties.

Here we go! You can only see the fruits category in this look up.

This was small post to show you how the lookups can be added in the forms by reference field group field.

Tuesday, September 1, 2015

Methods on Form and Datasource level AX 2012

As we have seen in our previous few posts that in DYNAMICS AX, we have number of methods that can be overridden on FORM as well as at DATASOURCE level. The primary purpose of overriding the methods at FORM level, DATASOURCE level or Field level is to perform User actions.

User actions on a form are input through mouse pointers and keyboards. I would recommend you to go through this MSDN post  to understand and learn about recognized events and their sequence.

It is always a best practice to write the code at class level so that it can be re-used. In dynamics ax, you can see number of Classes. already defined for different purposes. The methods of Classes can be used in Tables or Forms and also we can apply object-oriented principles such as Inheritance, Polymorphism, Encapsulation etc.

For example, while doing student course enrollment or student registration, we have number of common methods related to Student Entity. We must encapsulate these methods in Student Class and reuse them in Student Table and Student Form.  Let's say a registration number is generated every time there is entry in Student Table, the logic of generating the registration number must be placed in a class so that if a user has been given the facility of registering the Student at different forms, it should invoke every time the same method defined in a Student class.

Therefore, we should always try to write lines of code firstly at Class level  and secondly at Table level as much as we can.

You can also see the same methods while overriding the methods for DATASOURCE level that are already available at Table level. I am going to share with you a snapshot as shown bellow where you can see few same methods at Student DATASOURCE available for overriding that are also available for overriding at Student Table level such as validateWrite() and validateDelete().


Since you must have an idea after going through MSDN posts that validateWrite and validateDelete performs validations before writing or deleting records respectively. The best place to define the methods that are available both at table level and form level is table level. However, based on any particular scenario, these methods can also be overridden at form level.

 For example, after defining the validateWrite() at table level, we can also define the same validateWrite() at DATASOURCE level. validateWrite() at DATASOURCE level will be invoked at first, then it will invoke the validateWrite() at table level  by invoking super(). We can find whether validation at table level returns true or false by invoking super() at DATASOURCE level.


There are a lot of problems and issues we can find in dynamics where we would require only little piece of code or some where we require no any code. Therefore, we should be aware of all the important methods and their proper usage and sequence. Also, some times you fix any issue to do an implementation only setting a property instead of writing code, so I will recommend you to go through all important properties and methods in the MSDN. I always try to keep my posts as precise and I can, I hope you enjoy reading my posts, I will be waiting for your feedback comments.



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.