Tuesday, December 16, 2014

Form datasource find record method

Form datasource find record method

Form datasource find record method to find and set that record as current. So, the user can easily identify the record.

We need to pass the table record as parameter to this findrecord method.

Syntax:

public boolean findRecord(Common record)

For example:


Here, I have added some code in the button click method to find the record in the form datasource. So, that result record will be focused as current record.

void clicked()
{
    Hari_ExamResult examResult;
   
    select firstOnly1 * from examResult
    where examResult.StudentName == 'Hari';
   
    if(examResult)
    {
        Hari_ExamResult_ds.findRecord(examResult);
    }
    super();
}

Result:



Thanks,
Hari

Monday, December 15, 2014

Create a new record in the opened form

Create a new record in the opened form


We can insert the record by using the below code. This is the normal procedure, creates new table buffer, assign values and call insert method.

void clicked()
{
    Hari_ExamResult  examResults;
    examResults.StudentName = "Zyx";
    examResults.Standard = "Sixth";
    examResults.ExamResult = "Pass";
    examResults.RollNo = 1004;
    examResults.insert();
    super();
}

Our scenario is how to add a new record when form opens. If you use the above code in this scenario we should call the below code after the insert method before the super method call.

    Hari_ExamResult_ds.research();
    Hari_ExamResult_ds.refresh();

Note: Here, form datasource reread method won’t work, because when we call the reread method, it won’t call the form datasource executequery method. But, if we call the research method, it will call the form datasource executequery method.

The best practice for this scenario is calling the form datasource create method.

void clicked()
{
    Hari_ExamResult_ds.create();
    Hari_ExamResult.StudentName = "Zyx";
    Hari_ExamResult.Standard = "Sixth";
    Hari_ExamResult.ExamResult = "Pass";
    Hari_ExamResult.RollNo = 1004;
    Hari_ExamResult.insert();
    Hari_ExamResult_ds.reread();
    Hari_ExamResult_ds.refresh();
    super();

}

Please use the form datasource create method to create the records when form opens.

Filtering records

Filtering records

Filter the records is the important part to display the data. By using the filter we can display the necessary data and avoid showing the unnecessary data based on the requirement.

In AX 2012, there is a default filter functionality. To use default filter select the form grid and press the ctrl+g shortcut to show/hide the filter options in the grid and then you can enter the values and press the enter key to filter the record.




We can achieve this functionality by using the x++ code.

For example, we need to filter the student results by pass, fail and all option.
I have added one combo box and grid in the form. Based on the combo box selection, I am filtering the student exam results.


Step 1:

Add the unbound combo box with the enum type. So, we can filter the records based on this combo box selected value.

Step 2:

Declare the query build datasource and query build data range variables in the form declarations section.
public class FormRun extends ObjectRun
{
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr;
}

Step 3:

Add the filter code in the combo box selection change event.
public int selectionChange()
{
    int ret;
    ret = super();

    qbds.clearRange(fieldNum(Hari_ExamResult, ExamResult)); //Clear the filter field range
    if(ExamResultCombo.valueStr() != '') //Check the combo box has value or not
    {
        qbr = qbds.addRange(fieldNum(Hari_ExamResult, ExamResult)); //Set the filter field
        qbr.value(ExamResultCombo.valueStr()); //Set the filter value
    }
    Hari_ExamResult_ds.executeQuery(); //Execute the form datasource query to apply the filter

    return ret;
}




Some other useful functions like
qbds.clearRanges(); //To clear all ranges

qbr = qbds.findRange(fieldNum(Hari_ExamResult, ExamResult)); //To find the field range already exists or not



Once you understand this code, you can apply this code for different scenarios.

Please try the below filtering records functionality to improve your knowledge in the filtering records.
  1. Equal
  2. Not equal
  3. Like
  4. Like after
  5. Between
  6. Or
  7. And
  8. Empty
  9. Not empty
  10. Get all datasource names
  11. Get all datasource ranges
  12. Clear all ranges
  13. Clear particular datasource range
  14. Less than
  15. Greater than
  16. Less than or equal to
  17. Greater than or equal to
  18. Range is exist or not
  19. Filter is exist or not
  20. Find or create range
  21. Find or create filter
  22. Query build data source. To string
  23. Find group by field
  24. Find field

Sorting records



Sorting records

Sorting is the most important thing when display the data to the user. The user mostly prefers sorting functionality in the grid forms. AX 2012 has inbuilt functionality to sort the records in the grid by simply clicking the header of the grid column. Multiple sorting is not supported in the AX 2012. For example sort the fields by class and student name. Only single field sorting functionality is working in AX 2012.
As per the below example, we need to sort the record by student name. So, we should add some code in the form datasource init methd like below.


public void init()

{

    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, StudentName), SortOrder::Ascending);

}


We can also clear the sorting functionality by calling the form datasource sortClear method like below.

void clicked()

{

    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();

    Hari_ExamResult_ds.executeQuery();

    super();

}


We should call the form datasource execute query to reflect the changes.

We can change the sorting field by using the below code.
First, clear the existing sorting field then add new sorting field.

void clicked()

{

    Hari_ExamResult_ds.query().dataSourceNo(1).sortClear();

    Hari_ExamResult_ds.query().dataSourceNo(1).addSortField(fieldNum(Hari_ExamResult, Standard), SortOrder::Ascending);

    Hari_ExamResult_ds.executeQuery();

    super();

}

 

We can use this code logic to achieve some sorting related business requirement

Tuesday, October 28, 2014

Date range conditions and between operator in AX 2012

I faced some logical issues when I work with the between ranges. So, I just like to share my code logic for your references.

Between operators

AX does not support between operator in select statement. But it is mostly using operator in SQL queries.

For example, find the persons between the age 20 to 30, we can use between operator like below statement

SELECT * FROM Persons WHERE Age BETWEEN 20 AND 30

The above SQL query return the result set that persons between the age 20 and 30.


In AX, we don’t have other options. So, we need to use the basic logic like the below statement

select * from persons where persons.age >= 20 && persons.age <= 30;


Date range:

We can find the date is in the particular date range by using the below statement. For example, if we need to find, what are the courses conducted in the particular date. We can use the below statement.

select * from courses where today() >= courses.startdate && today() <= courses.enddate;


Date ranges overlap:

It is little difficult logic. Find the date range is match with the other date range. For example, find the particular week active employees. (In other words, find the active employee list for the particular week)

select * from employees where employees.validfromdate <= endate && startdate <= employees.validtodate;



Wednesday, September 24, 2014

Form data source link types - Active, Delay, Passive, Inner join, Outer join, Exist join, Not exist join

Form data source link types

Form data source link type is a property of the form data source. We can add more than one tables as a data source to the form. Those data sources should has the table level relation, So, then the developer no need to work on the coding part to find the relation records. For example, if we create the order form, that order form has orders and order details tables as form datasources. We can add both tables as a data sources to the form.

The parent table and child table should has the table relation. So, once we add these tables in the form as data sources. We can select the child table data source and mention the parent table name in the join source property of the child table form data source property.

Example:

Here, I have created two tables Hari_Order and Hari_OrderDetails. Hari_OrderDetails has the foreign key of Hari_Order table Key is OrderNo.

Hari_Order table


Order No
Customer Name
Ord 2
Ram
Ord 1
Hari
Ord 3
Vithyaa
Ord 4
Uma

Hari_OrderDetails

Order No
Product Name
Product Description
Ord 1
Prod 1
Product One
Ord 1
Prod 2
Product Two
Ord 1
Prod 3
Product Three
Ord 2
Prod 1
Product One
Ord 2
Prod 2
Product Two
Ord 3
Prod 1
Product One

Set the join source and set the link type

Table relation


Use join source and link type


Active

Active link type update the child data sources without any delay when you select the parent table record. When you deal with more records it will be affect application performance.


Delay

Delay form data source link type is also same as active method the different is delay method won't update immediately when you select the parent record. It will update the child data source when you select the parent table, Ax use pause statement before update the child data source. For example, if we are dealing with lot of records so, when the user click or scroll the order, order details will update without any delay if we use active method.

So, We can use delay method because of performance improvement.



Passive

Passive form data source link type won't update the child data source automatically. For example if we select the parent table order then order details child data source won't update. If we need to update the child data source we need to call the child data source execute query method by program (code).



The order details grid is empty. If we need populate the child data source (order details) then we need to call the Hari_OrderDetails_ds.executeQuery() method in the parent table Hari_Order form data source active method. We can add separate button "Populate order details" and call the code Hari_OrderDetails_ds.executeQuery(). So, if the user need to see the order details then the user update by click the "Populate order details" button.


Inner join

Inner join form data source link type displays the rows that match with parent table and child table. For example if the order doesn't has any order details then the order will not be display.

Here, Order 4 does not has the order details records, so it is not coming in the order grid.


Outer join

Outer join form data source link type will return all parent records and matched child records. It will return all rows in the parent table. Here, Order 4 doesn't has the child records (order details) but it is populating in the order grid. It is the difference between inner join and outer join.

Here, Order 4 is coming even order 4 does not has the order details.



Exist join

Exist join form data source link type return matched rows of the parent table. It behaves like inner join but the different is once parent row matched with child records then stop the process and update in the grid, Ax won't consider how many records in child table for the parent row.

Here, Order 4 is not coming because Order 4 does not has the order details.


Not exist join


Not exist join form data source link type is totally opposite method to exist join. It will return the not matched parent records with child records.

Here, Order 4 is coming because order 4 does not has the order details.



Each form data source link type has different behavior. Active, Delay and Passive are one category and Inner join, Outer join, Exist join, Not exist join are another category. So, please understand the behavior and choose the link type based on your requirement.


Thanks,
Hari

Sunday, September 21, 2014

Form datasource

What is form datasource

Form datasource is a data source (source) of the form. The forms are displaying the database table records to the end user by using the form datasource. For example, if you open the vendor list screen, the form will display the vendors list by fetching records from the database VendTable table. Here VendTable is the form datasource.

The form displays the datasource fields. Type of form datasources are AOT query, table and view. The form has two types of controls that are bound controls and unbound controls. Bound controls are linked with form datasource fields, but unbound controls are not related with form datasource fields. The form datasources are having link with database. So, it is having connection with database. It supports form to add, edit and delete the records.

Types of form datasources

  1. AOT Query
  2. Tables
  3. Views

Add datasource to the form

In AX, It is very easy to display or update or delete the records in forms. It is very simple. Follow the below steps to display the records in the grids.
  1. Add new form
  2. Click and drag a table to form datasource node or right click on the form datasource and click new datasource and select the table name in table property of the newly added form datasource
  3. Add grid control in the form design node
  4. Click and drag the newly added form datasource table fields to grid control

We can control the forms to add, edit and delete the form datasource records by using the AllowCreate, AllowEdit and AllowDelete form datasource properties. For example, if you want to only display the records but don’t allow the user to create, update and delete the records then please set “No” value to the form datasource properties AllowCreate, AllowEdit and AllowDelete.

Please refer the below screenshot


Saturday, September 20, 2014

Method overloading in Ax 2012

Method overloading:

Method overloading is the one of the oops concept. Method overloading is same method name but different parameters or different parameter data types in a class.

For example:

Private real GetSalary(int empId)
{
…………….
}

Private real GetSalary(int empId, boolean plusBonus)
{
……
}

The above methods are same name “GetSalary” but parameters are different. We can call this method like below

salaryAmount = GetSalary(3426);

or

salaryAmount = GetSalary(3426, true);

Unfortunately, X++ does n’t support method overloading, but it supports options parameters. The optional parameter mimics like method overloading. In X++ we can do the above business logic like below code by using optional parameters.

Private real GetSalary(int empId, boolean plusBonus = false)
{
……………
}

Here, plusBonus variable is the optional parameters.

We can call the above method like below code

salaryAmount = GetSalary(3426); // The default value “False” will be set to plusBonus parameter

or

salaryAmount = GetSalary(3426, true);



We can order optional parameters to end parameter(s). In other words the optional parameters should be placed end to the non optional parameters. We can't place non optional parameters next to optional parameters. For your reference please refer the below code. The below code is not supported.

Private real GetSalary(boolean plusBonus = false, int empId)
{
……………
}


Note: C# supports both method overloading and optional parameter concepts.

Wednesday, August 27, 2014

Local functions

Local functions

Local functions are the functions that placed in another method. In AX, we can add local functions inside to the job or class methods but we can’t add local functions inside the local function, it is restricted. Local functions are used to separate the business logics. The best practice is to avoid to use local functions, instead of this we can create private methods.
 

Create local function:

Local function should be placed end of the declaration part.
Note: we can’t declare the variable next to the local functions.
 

Scope of variables:

Local function can access the method variables. For example, Localfunction1 can access the Hari_LocalFunctions method i variable. But Hari_LocalFunctions method can’t access the local function variables (Localfunction1 function j variable)
 

Calling local functions:

We can call the local function as usual method of calling method or function like Localfunction1().
We can call the local function from top level declared local function. For example, we can call the localFunction1 local function from localFunction2 local function, but we can’t call the localFunction2 from localFunction1 local function. Because the localFunction2 is declared next to the localFunction1 local function.
Local function is also supporting recursive function calling method. Note: We should be careful when we using recursive function.
 

Example code:

I have created the job for your better understanding.
 
static void Hari_LocalFunctions(Args _args)
{
    int i = 1;
    void localFunction1()
    {
        int j = 2;
        info(strFmt('Method 1 - %1', i));
    }
    void localFunction2()
    {
        info(strFmt('Method 2 - %1', i));
        localFunction1();
    }
    ;
    localFunction1();
    localFunction2();
}

Sunday, August 17, 2014

Navigation

Navigation

Navigation helps the end user to navigate to forms or reports easily. In AX navigation are grouped by application modules. For example the accounts receivable navigation found under the Application receivable module. We can add new forms or reports in the navigation. It will reflect in the area page or navigation pane. The list page and area page are navigation pages. Navigation pages means this pages contains links to other pages. We can separate the navigation section by the followings.

Address bar

Address bar is displayed in the top of the page like the browser's address bar. It displays the the address very friendly to the end user to understand the form flows. For example: Accounts receivable\Common\Customers. We can't change the order of the menus and menus text directly in the address bar but, we can change these by changing the menus and menu items. Address bar contains forward, back and history buttons.

Application module

Application module is a collection of business functionality is mapped together. For example, accounts receivable is a application module, this module contains the accounts receivable related activity forms and reports. We can navigate or change to another application module by clicking the drop down of the address bar or by using the navigation pane.

Area page

Area page is the main and first page to the application module. The area page contains the links to the forms or reports. All forms and reports links are together in the area page.

List page

List page is a page that displaying the data in the grid. The user can open the details page (content page) by double clicking the data of the list page. The list page is also consider as navigation page.

The design elements of a list page

Content page

Content page is the details page of the information. The insert or update screens is also called as content page. It displays the content of the information. For example customer creation forms is the content page. Sometimes, the content page is opened from the list pages. The content page may contains action pane, grid and datasources.

Navigation pane

Navigation pane displays left side in the application workspace (AX client). It display the selected application modules forms and reports links. It helps the end user to navigate to the form or reports easily. This navigation pane has the following sections. Please be careful to choose the following section when you add the newly customized forms or reports. For example, if you want to add the customized setup form, please choose the setup section and add your form under this section. So, the user don't  get confused.
  • Favorites
  • Area page
  • Common
  • Journal
  • Inquiries
  • Reports
  • Periodic
  • Setup

Favorites

The end user can add mostly using forms and reports under the favorites section by right clicking on the forms or reports link and select the add to favorites menu options. By using this favorites, the user no need to spend more time to find the mostly using forms.

Area page

Area page section links for navigate to area page.

Common

This section contains the mostly using forms. So, the user no need to find in other sections.

Journal

Journal related forms are listed under this section

Inquiries

Inquiry related forms are listed under this section

Reports

All reports are listed under this section.

Periodic

The forms that used to run based on the schedule like monthly, weekly or daily.

Setup

Setup related forms are listed under this section. The setup forms contains the parameters to achieve the business logic.

Role center page

Role center page is the first or main page to the Enterprise portal. For more information about the role center page, please refer this link.

Monday, August 11, 2014

AX 2012 - Development workspace

AX 2012 - Development workspace

Development workspace is a work area to developer for customize the forms, reports and menus. Development workspace contains AOT, Label editor and developer related tools. MorphX is a AX 2012 developer IDE and it works in development workspace. Development workspace only works if you installed the developer licenses otherwise the option should be disabled. We can work with maximum eight workspace. It may be development workspace or application workspace or both (For example: 3 development workspace and 5 application workspace). Application workspace is a user interface for end user. Developer customization works will be displayed in the application workspace.

Open the development workspace

Method 1:

Default, when you open the AX 2012 the application workspace will be displayed. But, the developer needs to open the development workspace first instead of application workspace. So, we can add -development parameter in the target path like below.

Right click on the AX 2012 shortcut icon and change add the -development in the target path like "C:\Program Files\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe" -development

Method 2:

Click the windows menu on the top right in the application workspace and click the Development workspace menu or simply use the shortcut Ctrl+Shift+W for development workspace Ctrl+W for application workspace.

Method 3:

We can open the development workspace by using x++ code like below. For example we can add button in forms to open the development workspace by clicking this button.

static void OpenDevWorkspace(Args _args)
{
    int hWorkspace;
    hWorkspace = infolog.createDevelopmentWorkspaceWindow();
}

infolog class is used to retrieves the workspace information like license code, open the development workspace, open the application workspace, shutdown the client, read the AOT elements, etc..

Thanks,
Hari

Sunday, August 10, 2014

MorphX and Intellimorph

MorphX & IntelliMorph:

Here, i explain what is MorphX and IntelliMorph in AX 2012.

MorphX:

MorphX is an integrated development environment (IDE) of Microsoft Dynamics AX. MorphX is used to modify forms, reports, tables, menus, etc. If we need to create or modify (customize) AX objects like forms and reports we need to use this MorphX IDE. MorphX IDE only works if you installed the developer license in your Microsoft Dynamics AX.

MorphX is an easy tool to developer. The developer can create forms, menus, tables, manage labels and reports in easy manner by using this IDE.

X++ is a object oriented programming language. It is used in MorphX IDE.

Please refer the below link for full details about MorphX.
http://msdn.microsoft.com/en-us/library/aa853691.aspx

IntelliMorph:

IntelliMorph is an runtime environment in Microsoft Dynamics AX. It helps lot to developer. It works that how user interface is displayed to the user. I mean the appearance. The developer adding the fields in the forms but the IntelliMorph technology is displaying the fields in the form with correct appearance like width, height, etc.. So, it reduces the developers work. The developer no need to worry about how the controls appears on the forms and reports.

For example:
If the developers set column width to the width property of the the grid mean the grid width should appear based on the form's width. Mean the grid occupy the full width of the form or parent control width. As per this settings the IntelliMorph works to display the grid in the full size.

Everything related about appearance of the form is managed by IntelliMorph.


Thanks,
Hari

Saturday, August 9, 2014

AX 2012 - Development introduction Microsoft certification - MB6-869

Hi Friends,

Microsoft development certification is worth full and companies are expecting the employees gets the Microsoft certification. The companies are benefited by having certified employees. The companies consider the certified candidate in the recruitment time. We can improve the knowledge by doing the certification.

In AX 2012, Microsoft conduct the development certification (MB6-869). Here, i have included the skills mentioned for this certification.

1.       Understand Microsoft Dynamics AX 2012 architecture (13%)
a.       Identify key development features and functionality
                                                               i.      Development workspace, IntelliMorph, MorphX, object-oriented design, navigation
b.      Demonstrate understanding of the data architecture
                                                               i.      Work with data in forms, sort records, filter records, find records
c.       Demonstrate understanding of architecture components
                                                               i.      Layers, models, labels, Help system, reporting
d.      Work with customization tools
                                                               i.      Use MorphX to customize the user interface, use the X++ editor to develop customizations, identify best practices, use the Type Hierarchy Browser and Type Hierarchy Context tools, use the reverse engineering tool
2.       Manage the data dictionary (13%)
a.       Work with MorphX, the Application Object Tree (AOT), and projects
                                                               i.      Work with development projects, features of the AOT, Microsoft Visual Studio projects node, objects in the data dictionary, navigate the AOT and data dictionary
b.      Work with tables and relations
                                                               i.      Table structure and components, fields, field groups, indexes, delete actions, create tables, create relations, primary keys, foreign keys, surrogate keys
c.       Work with data types and base enumerations
                                                               i.      Primitive types, extended types, create data types, use data types, create base enumerations, use base enumerations
d.      Work with maps and views
                                                               i.      Map functionality, map advantages, view functionality, view advantages
3.       Manage the user interface (13%)
a.       Work with menus and menu items
                                                               i.      Create and use menu items, menu functionality, create menus
b.      Manage forms
                                                               i.      Data sources, design, document view, edit data in a form
c.       Work with forms
                                                               i.      Form types, list pages and list page metadata, work with the action pane, form parts
4.       Manage security (11%)
a.       Work with role and task based security
                                                               i.      Identify key concepts, terms, and benefits; work with roles, process cycles, and duties; work with privileges, entry points, and permissions
b.      Understand security concepts and settings
                                                               i.      Default security settings, sample security settings
c.       Work with XDS and server enforcement of security
                                                               i.      Server-based code authentication, data security filters, org model, effective date
5.       Work with X++ control statements (13%)
a.       Work with variables
                                                               i.      Declaration, simple data types, composite data types, arrays, containers
b.      Work with operators
                                                               i.      Assignment operators, arithmetic operators, relational operators, operator precedence
c.       Work with conditional statements and loops
                                                               i.      If…else, ternary, switch, while loops, do…while loops, for loops
d.      Work with communication tools
                                                               i.      Print, boxes, infolog, dialog
6.       Manage objects and classes (12%)
a.       Work with classes, objects, and inheritance
                                                               i.      Define key attributes, method access control, extend a class, expression operators for inheritance, reference object methods, method types, inheritance among tables
b.      Work with scoping, events, and parameters in X++
                                                               i.      Scope of objects within a class, events in X++
7.       Access the database (15%)
a.       Retrieve data
                                                               i.      Table buffers, select statements, field lists, while select statements, sort, joins, cross-company data access
b.      Manipulate data
                                                               i.      Insert, update, insert_recordset, update_recordset, delete, delete_from, transaction tracking system
c.       Work with queries
                                                               i.      Execute a query, build a query, QueryBuildDataSource, QueryBuildRange
8.       Manage exception handling (10%)
a.       Work with exceptions and optimistic concurrency exceptions
                                                               i.      Handle errors
b.      Work with throw and try/catch commands
                                                               i.      Handle errors

Please go to this link and get full details about the MB6-869 exam https://www.microsoft.com/learning/en-us/exam-mb6-869.aspx

Please refer the below link to prepare for AX 2012 development introduction certification. The author of the below link, listing the skills mentioned in the Microsoft certification site and linked the topics with content for further study

http://axandhellisfunafterall.blogspot.in/2014/02/exam-mb6-869-microsoft-dynamics-ax-2012.html

Thanks,
Hari