Search This Blog

Tuesday 20 November 2012

Preview Pane In Dynamics AX 2012

A preview pane is the part of a list page that shows additional information about the highlighted record in the list. A preview pane is optional and is located under the list page grid.

Note:Preview Pane is just like FactBox of  type InfoPart.For making Preview Pane we just need to set the property of this part inside the part node of the form of part location to PreviewPane.

Below in the image is the Preview Pane in a list page.














Steps for Creation of Preview Pane is very simple we have to first made a info
part as we made it for FactBox.

Here is the link below on how to make the InfoPart.

http://codingchamp.blogspot.com/2012/11/fact-box-in-microsoft-dynamics-ax-2012.html

Than we have to make a Display Type Menu Item.In which we set object type to InfoPart and object to name of the infopart.

Than We go to part node of the Form and than right click and than select new refrence name and than specfied the name of the menu item and than setting part location to PreviewPane.

If you want to explore more for the preview pane than here is the link below.

Preview Pane

Thanks

Muhammad Zahid.
 

Friday 16 November 2012

Fact Box in Microsoft Dynamics AX 2012

Fact Box is basically use to show the data related to the selected record.

The FactBox pane is the area of a form where a part that you add to a form appears as FactBox. A part is a specialized type of control that can retrieve and show additional information. When you view the form, the part appears as a collection of read-only data called a FactBox. For information about parts.

To have a FactBox appear in a form, the form must include a FactBox pane. The following types of forms include a FactBox pane:
  • List pages
  • Details forms
The FactBox pane is optional and if the form does not have any parts, the FactBox pane does not appear. A FactBox pane can show more than one FactBox.
The parts you add to the FactBox pane create FactBoxes that show additional information about the record that appears in the form. The FactBoxes enable you to view related information without having to find and open a separate form. In addition, you can configure the part so that the contents of the FactBox update when you move to a new record.
 
For Fact Boxes we basically uses the Parts.There are three types of parts in Microsoft Dynamics AX these are:
 
1.Info Part.
 
2.Form Part.
 
3.Cues.
 
1. Info Part:
 
An info part is a type of part that you use to add a collection of fields and values to the FactBox pane of a form, or the preview pane of a list page
 
In Info Part we just specified the Query and in the layout node of the info part we just add fields and in the properties of these fields and than specified the datasource name and the field name.
 
Below is the image of the Info Part on the Form.

















Below is the info part in the AOT.

























For Showing the info part on the forms we just made infopart inside the Parts->InfoPart node of the AOT and than create a menuItem with object type=InfoPart and object =name of the infopart and than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.

Below is the parts node of the Form HcmWorkerListPage and the properties of the selected part.





 note:Info Part can be shown on both the cleint and Enterprise Portal. For Implementation of Info Part you can see my other post.
Just click on the below link

Info Part In Microsoft Dynamics AX 2012.

2. Form Part:

A form part is a pointer to an existing form. You use a form part to make the form appear in the FactBox pane of a form, the preview pane of a list page, or the enhanced preview of a control.
Take care to select a form that fits the location where the form part appears. For example, a form with a large grid and several controls might not fit the space available for a FactBox or enhanced preview. Typically, you select a form that was designed for use in the FactBox pane, preview pane, or enhanced preview

Below is the image of the FactBox of type FormPart.










We use Form Part to show the form in fact box.Form part is very simple we just specified the name of the Form in the property of the FormPart.

Below is the image of the Form Part its properties in the AOT .


For Showing the formpart on the forms we just made formpart inside the Parts->FormPart node of the AOT and than create a menuItem with object type=FormPart and object =name of the formpart and than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.

3. Cues and Cues Group:

Cues are basically use to show the number of records against the selected record and sum of the particular field.However calculation for the sum is optional.

For example we go to the list page which contains all the customers than we select the customers than in the fact box their will be the cue which shows the number of sales orders against that customer and the sum of particular field  that we have presented in the Fact Box.

Note:Cues can not be shown alone on the fact box.We first have to make the Cues and make a Cues group and than drag and drop our Cues into the Cues Group.

Below is the image which shows the Cues how they looks like.






 
 
As you can see in the image that the cues are in hyper link this because when we click on that link a new form will open with the related information like customer sales orders,cutomer open invoices etc.

Below are the steps for creating the Cues and CuesGroup

1.For Creating Cues we have to first create the menu item and in the property sheet of the menu item we have to set the name of the form and the Query which retrieves the record against the select record.

2.Than we have to go to the parts->Cues node in the AOT and create new Cue and in the property sheet of the Cue we set the name of the menuitem that we have just created.and if we want to show the sum of particular field than we will set the property calculate sum =yes and table=table name and field =field name as you can see in the below image.

note:Specifies whether to show a sum for the cue. The default value is No. To calculate a sum, the field must be one of the following Extended Data Types:
  • AmountCur
  • AmountMST
In addition, the table in the data source must have a field of type CurrencyCode.
 



3.Than we go to the Cue Group node and than create new Cue Group and  than drag and drop the Cues to the to the newly created Cue Group.

Below is the image of the Cue Group and its properties.



4.Than we have to make a menuitem and than setting its object type to CuesGroup and   object to  name of the Cue Group.

5.Than we go to the parts node of the form and than right click and than select new refrence name and than new part refrence and than specfied the name of the menu item and than setting part location to Auto.
 
 
 Below are the some links for Deep Drive in Fact Boxes:

Fact Box

InfoPart

FormPart

Cues and Cue Group


Thanks,

Muhammad Zahid.


 

Thursday 1 November 2012

Field Group In Dynamics AX 2012

Field Group is basically use for logical grouping of data for example we require employee personal information on different forms than we just put fields related to employee personal information into the  field group and than put that group field on to the form.Than Automatically show the fields of Employe Personal info on the form.

The benefit of the field group is that when we want to add or delete value from the field group it automatically reflects on the form which using that field group.

The side effects of the field group is that we can not modify the single form which uses the field group.Than we have to remove field group from that form and put individual fields.

For more exploration on field group here is the link below:

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

 

Wednesday 31 October 2012

Coding Best Practices In Dynamics AX 2012

There are some coding best practice strategies that every one should follow to avoid Best Practice Errors.

1. Use camel cases for all the member variables i.e serverClass (First alphabet of the work should be small and second alphabet should be capital).

2. Use Pascal Case Naming  Convention for application Object Tree Elements.

e.g:AddressCountryRegion

First letter of each word should be capital.

3. Parameters Names in Methods should start with _ (underscore).

4. Do not encode the type of a variable in its name eg strName (This is wrong).

5. Do not use multiple comments use only single line comments.No matter how many lines the comment contains.

6. Do not use comment at the end of the line.Unless the comment is very small
e.g: int count; //-1 indicates.

7. Remove Todo comments in advance of a release.

( Todo Comments are basically the comments of code that this code contains bug we will fix it latter or etc.)

8. XML Documentation is  basically the Description  of the method and  its parameters.

We must place XML Documentation above every method.

To create the XML tags place /// above the method or right click
scripts->documentation->HeaderTemplate.

9. Put the method calls inside the conditions so if call are fails than method calls cost will reduce.This is benefit of taking less time consuming.

10. Use field list in select statement.

11. Use Extended Data Types whereever possible.

12. For constant values that are use in multiple places in code you should use #define to define macro that has the constant value.

Example for defining Macros.

#define. MacroName('value')

Example for using Macros.

variable=#Macroname.

13. Use local variables as more as possible.

14. Avoid Global variables as more as possible.

If  you want to explore more in Coding Best Practices than here is the link below:

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

Thanks

Muhammad Zahid.
 

Friday 19 October 2012

Unit Test Framework In Microsoft Dynamics AX 2012

The Unit Test framework is tightly integrated into the MorphX IDE of Microsoft Dynamics AX. This integration is very important to test-driven development (TDD) because a unit test can be created alongside the feature code it is testing.

What is a Unit Test:

A unit test is code that verifies that feature code has been implemented correctly. If you adhere to the principles of TDD, it is best for the developer who is writing the feature code to first write the unit tests. This puts emphasis on how feature code is consumed and creates a more user friendly application programming interface (API). A unit test, in the context of the Unit Test framework, includes test cases, how test cases are staged with data, and the organization of test cases. A test case is a class that extends the SysTestCase Class class. You can add test methods to test each requirement of the feature code. You should execute test cases when code is changed.

Some Important Points:

Every test case class should extend  SysTestCase Class.

For testing purpose you can write multiple methods for single actual method in code.

For Classes their should only one class for testing a single class.

Name the test class same as the class followed by test in the end.

Name of the method in the test class should also contains test  in the start.

We write Unit Test for classes and tables only.

Always Testing will be done on Blank Database.

The attribute that must be placed on the unit test case class is:

[SysTestTargetAttribute('SysDictTable',UtilElementType::Class)]

The attribute that must be  placed above the method of the test case is:

[SysTestMethodAttribute]

Methods for Setting Data:

Two types of methods are use for setting up data.These are:

1. Setup Method.

2 Setup Test Case Method.

1.Setup Method:

Setup Method runs before every Test method.For some times we usaually want fresh data so we write code in setup method.It works like this:First setup method executed than test method executed than tear down method executed than again setup method executed with fresh data than second test method executed and so on.

2.Setup Test Case Method:

Setup Test case method runs only one time when test class is executed.In case of setup test case method it executed only one time and than tear down method for setup test case method will execute in the end.

note:Due to some issues we usually dont use i.e override setup test case method we only use setup method.

Tear Down Method:

Tear Down method is basically use to flush out data.We normally dont override this method.It manages Automatically.

A test method will typically contain several assertions that are required to hold true,for the test to be successful.

Note: The use of the assertEquals method.This method,and other assert methods,are available as part of the SysTestCase framework.These methods also have an optional string parameter called _message,to specify the message that would go into the infolog.If the assertion fails.The following is list of available methods:



























Now I will show u the simple example on how to use the Unit Testing.

Create a simple class that contains add,subtract and multiply methods.

Now Create the Unit Test to Test this classes.The original class on which I have made these methods is Calculations.Now for unit test first we will override the setup method.



public class calculationtest extends systestcase
{
calculation obj;
}

pulbic void setup()
{

 obj=new calculation();

super();

}

public void testadd()
{
this.assertequal(3,obj.parmadd(1,2));
}
public void testmultiply()
{
this.assrtequal(9,obj.multiply(3,3));
}

Class Declaration:

[SysTestTargetAttribute('calculation',UtilElementType::Class]
public class calculationtest extends SysTestCase
{
calculation obj;
}

Methods:

[SysTestMethodAttribute]
public void testadd()
{
this.asserEquals()3,obj.add(1,2);
}

[SysTestMethodAttribute]
public void testsubtract()
{
this.assertEquals(1,obj.subtract(1,2));
}

[SysTestMethodAttribute]
public void testmultiply()
{
this.assertEquals(9,obj.multiply(3,3));
}

Running Test Cases:

Now right click the test class i,e is calculationtest and than go to add ins than click the run test tests as
you can see in the below image:

 
 
Now after running the unit tests you can see in the above image that the how much methods are runs how much are fail as you can see in the image.
 
 

 

You can also record the code coverage of the code just click on the parameters button as you can see in the above image.

A new screen will open.Now check the checkbox record code coverage and record number of records.as you can see in the below image.






















Now click on the Listener as you can see in the above image and select infolog.This is for when some exception occur than it will be show in the infolog.

Below is the screen for the infolog.

Now close the above form and than again run the unit test and than click the details button as you can see in the 3rd last image and a new form will open and where you can see the code coverage.

The recomended code coverage of the class should be 60%.

You can see the code coverage of my class in the below image:














You can also see the code coverage of the methods also.Just select your recently run testcase and than click the test button as you can see in the above image.

A new form will open which shows the code coverage of the methods as you can see in the below image.

 
Thanks
 
Muhammad Zahid.






Saturday 13 October 2012

Queries In Dynamics AX 2012

Types Of Queries :

There are three types of queries in dynamics ax 2012:
1. Inline Queries.
2. Aot Queries.
3. Queries objects and API.
1. Inline Queries:
Inline queries are similar to the Linq queries in dot.
In inline queries you need to create the table buffer.
Table Buffer is quite similar to the objects in classes.
In Dynamics Ax tables can also be treat as a classes where you can write your own methods.
Below is the simple example of inline queries.
CustTable custTable;
 select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000";
info(custTable.AccountNum);
I you want to show all the records in the info box than we use while statement
while   select AccountNum from custTable order by AccountNum where custTable.AccountNum>="1000";
{  
 info(custTable.AccountNum);
 }
We can also use aggregate functions  in  inline queries.
Here is the example given below:

 select count(AccountNum) from custTable where custTable.AccountNum>"1000";

info(custTable.AccountNum);

Joins in Inline Queries:
Lets make it little bit more interesting by using joins:
HcmBenefit hcmBenefit;
HcmBenefitPlan hcmBenefitPlan;
while select * from HcmBenefit join HcmBenefitPlan
where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId
{
info("%1,%2",hcmBenefit.BenefitPlan,hcmBenefitPlan.RecId);
}


Group By Clause in Inline Queries:


Group by clause is basically use when we use aggregate functions.Lets see an example:

while select count(RecId) from hcmBenefit
join Description from hcmBenefitPlan
 group by hcmBenefit.BenefitPlan,hcmBenefitPlan.Description
where hcmBenefit.BenefitPlan==hcmBenefitPlan.RecId
{
info(strfmt("%1,%2",hcmBenefit.RecId,hcmBenefitPlan.Description));
}


Inline Queries -Select Options :






If you want to explore more than you can refer to the following link:
 
 
Simple Insert,Update,Delete:
Insert:
Student  student;
student.name="muhammad zahid";
student.insert();
Update:
select forupdate from student where student.name=="muhammad zahid"
if(student.RecId>0)
{
ttsbegin;
student.name="Baber Tareen";
student.update();
ttscommit;
}
note:The if check was only to check that if the record exist or not that i have fetch.You can remove this if check if you want.
Delete:
select forupdate from student where  student.name="Baber Tareen";
if(student.RecId>0)
{
ttsbegin;
student.delete();
ttscommit;
}
Insert And Update multiple records at a Time:
For inserting multiple data at a single time we use insert_recordset and for updating multiple data at a single time we use update_recordset 
update record set
insert_recordset:
insert_recordset myTable(myNum,mySum)
select myNum,sum(myValue) from anotherTable
group by myNum where myNum <= 100
note:here mytable is the table in which we are inserting the bulk record and the fileds are those in which we inserting data and than the select query which fetch the record whic we are inserting in our table.    
update_recordset:
update_recordset student setting
name="zahid";
the above code will update all the names fields to zahid.You can also use where clause to update the selected record set.
The pseudo code for the update record set is:
update_recordset my TableBuffer setting
field1=1,
field2=fieldX + filedY
where field1==0

 

AOT Queries:

AOT Queries are those queries that we made in AOT by the help of the wizard.

below is the image of the AOT Queries.







Calling Aot Queries:
 
HcmBenefit hcmBenefit;
 
HcmBenefitPlan hcmBenefitPlan;
 
Query q=new Query(queryStr(BenefitQuery));
 
QueryRun qr=new QueryRun(q);
 
while(qr.next())
{
hcmbenefit=qr.get(tableNum(hcmBenefit));
 
hcmBenefitPlan=qr.get(tableNum(hcmBenefitPlan));
 
info(strfmt("%1,%2",hcmBenefitPlan.Description,hcmBenefit.RecId));
}
 

Query Build API:

Query:
 
Contains the definition of the query.Can consist of one data source or several data sources if they are related.
 
Query Run:
Class use to execute the query and loop through reuslt.
 

Query Build DataSource:

Links to one datasources in query.
 
Query Build Range:
 
Enables the end user to limit the result by adding a value in the specified query range.
 
QueryBuildFieldList:
 
List of all the fields in data source.
 
Query Build Link:
 
Links two data sources in a join.Is set on the child data source.
 
Using Aggregates and Sorting:
 
 
 
 
 
Using Joins:
 



 

some usefull links so you can deeply explore.
 
 
 
 
Thanks
 
Muhammad Zahid. 
 
 
 

Thursday 11 October 2012

Map and MapEnumerator Class

Map Class:


                       The Map class lets you associate one value, that is, the key, with another value. Both the key and value can be any valid X++ type. This includes objects. The types of the key and the value are specified in the declaration of the map. The way in which maps are implemented means that access to the values is very fast.

we can also assign our hard coded key value and value in maps.

I will show you the little example on how to implement Maps.This will make more clear concepts.

Map zahidmap;
 
zahidmap=new Map(Types::Integer,Types::string);
 
zahidmap.insert(1,"Muhammad Zahid");
 
zahidmap.insert(2,"Asim Saeed");
 
zahidmap.insert(3,"Baber Tareen");
 
if(zahidmap.exist(1))
{
info(strfmt("%1",zahidmap.lookup(1)));
}
 
if(zahidmap.exist(2))
{
info(strfmt("%1",zahidmap.lookup(2)));
}
 
if(zahidmap.exist(3))
{
info(strfmt("%1",zahidmap.lookup(3)));
}

In the above code I have just created the map with key value type=integer and value type =string
than I have inserted the key value and value into the map and than i have just made an if  check whcich checks that if this key is exist or not and by m.lookup method i just return the value against the key that I have passed into the parameter.

Output:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

 

MapEnumerator:

 
The MapEnumerator class allows you to traverse through the elements within a map.
 
Example:
 
This example is proceeding from the above created example.
 
As I have already created the map.Now in this example i will assign this map to the map enumerator.

MapEnumerator zahidmapenumerator;

zahidmapenumerator=zahidmap.getEnumerator();

while(zahidmapenumerator.movenext())
{
info(strfmt("%1",zahidmapenumerator.currentvalue()));
}

The outpur will be the same as you can see in the above image.

Thanks

Muhammad Zahid.