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!




No comments:

Post a Comment