Search This Blog

Thursday 20 December 2012

AIF Framework in Microsoft Dynamics AX 2012 Part 1

Following the features of Application Integration Frameworl in Microsoft Dynamics AX 2012.

. Enables companies to integrate and communicate with external business processes and partners.
 
. Exchange of data through formatted XML
 
. Formatted XML is referred to as a document
 
. Service can be hosted on
 
    . AOS
 
    . IIS
 

AIF Service Types:

 
There are following three types of  Services:
 

1. Document Services:

 
Query-based services that can be used to exchange data with external systems by sending and receiving XML documents
 

2. Custom Services:

 
Can be used by developers to expose any X++ logic such as X++ classes and their members, through a service interface.
 
 Example of Custom Services is Business Operation Framework.
 

3. System Services:

 
Provided by Microsoft Dynamics AX .System services include the query service,the metadata service, and the user session service.System services are not customizable ,and they are not mapped to any query or X++ code. 
 
 In this session i will explain only Document Services.
 

Document Services:

. The XML Document Framework contains these types of classes:
 
     . Axd<Document> classes (also known as an Axd class)
 
          . containg the business logic for related entities.
 
. Ax<Table> classes
 
    . abstraction of a table and encapsulate the business logic associated with creation and modification of records in the database table.
 

AXD Document Classes:

 
These are the main methods called when data is created or updated.
1.prepareForSaveExtended.
 
  .Called when records are created.
 
2.prepareForUpdateExtended.
 
 .Called when records are updated.

Docuement Service Operations:

.create
This item creates a record for a new item in the database.
 
.delete
 
This operation deletes a record in the database.
 
.find
 
This opearation searches for the specified database record.
 
.findkeys
 
This operation retrieves a list of entity keys that correspond to the specified search criteria
 
.read
 
This operation retrieves the specified record from the database.
 
.Update
 
This operation updates the record in the databaseOnly the fields that are contained in the message are updated.Values for all other database fields remain unchanged.
 

Implementation:

Now I will show you the implementation of the Application Integration Framework.
 
Note:In this session I am showing only the example of the Document Service of AIF.
 
Step 1:
 
First of all i have created the Project in which i have create two tables and then make relations between them.In the first table I  have created the employee table which contains the fields i.e emp date of birth,emp name,emp number and than I have created the employee department table in which i have created the fields employee department and employee experience.Employee is the parent table and employee department is the child table.Than made the Query to fetch the data from these tables.Note that i have created the outer join in the query to fetch all the records and than set the property update =  true because we will also update the record in this example.
 
you can see tables of my project in the below image:
 
 
 
 
 
 



















And in the below image you can see the Query that I have created you can also see its properties.

























Step 2:

Now we will go and create our document service .

just go to the tools->application integration framework->create document service

as you can see in the below image:
















 

 A new wizard will open.Now click the next button

A new screen will come and than select your query that you have created in early step.

You can see the below image.

 
Now click the next button.A new wizard will come here you can see the axd classes names that are generated and then select operations that you want to perform through this service. and then click on the checkboxes under axbc generation.These are the proxy classes need by the Application Integration Framework.

You can see the screen in the image below:





















Now click the next button. A new wizard will open and than click the generate button.This will create the new project which contains all the proxy classes that will be use by the service consumer.As you can see in the image below:

























Now we need to register that service as valid AX service.Just right click the service file that I have highlighted in the above project and than go to adds-in and than click the register service.It will take some time to register.

Now our service is ready but not yes accessible from the outside world we need to create the inbound ports.

just go to the System Administration -> Inbound ports.

A new screen will open as you can see in the below image:
















New click on the new button as you can see in the above image to create new inbound port.
And than enter the name of the port as i have highlighted in the above image and than check the
check box include exceptions in fault.Checking this checkbox is not necessary but its for development point of view that if during the insertion of data if some exceptions occur than we can easily see that.

Now click the Service operations button as you can see in the above image.After clicking this button a new wizard will open as you can see in the below image.

 
 

Now select the service operations that we have created in the project.These service operations will be consumed by this port.

After selecting the service operations close this wizard and then click the activate button as you can see the second last image in the above.

Now your service will be activate and is able to consume by the consumer code.After the activation of the service you will get the WSDL URI that will be use in the consumer code to refrence this service. As you can see the image below the generated WSDL URI.
















Now  the process of how to consume this service I will show this in the next part 2.
I hope this session will help you on how to configure AIF service.

Thanks

Muhammad Zahid.

 
 

Thursday 6 December 2012

Unit of Work Framework In Microsoft Dynamics AX 2012

Unit of Work Framework is use to commit number of records in a single Transaction.The main reason for introducing unit of work is that it is impossible to insert the lines table record before its header table  because there is a relation between the header table and the lines table.The Recid of the header table is comes as a foreign key in the child table.

Lets took an example as you can see in the microsoft dynamics ax there are two tables i.e custtransopen and custtransopenline.These two tables are related with each other CustTrabsOpen is the parent table and custtransopenline is the child table.

As you can see in the below image about  these two tables and there relations.


There is a common field on both the tables i.e amountcur.

In the parent table i.e in the custtransopen table this amountcur contains the total of the custtransopenlines amountcur.
Now we cant insert the records in the custtransopenline table because it needs the recid of the parent table i.e custtransopen and similarly we cant insert thet record first in the parent table i.e custtransopen because it needs the total amountcur from the custtransopenline.

To resolve this issue Unit of Work Franework is introduced.It allows to perform create, update and delete operations without worrying about the order of those and without a need to specify surrogate key values. It will all be done automatically in the kernel!

Now to show the Implementation of the Unit Of Work I have created two tables i.e invoiceheader and invoiceline and than made the relation between them.The invoiceheader contains the field i.e totalquantity which holds the total quantity of the invoiceline field i,e quantity.

Below image will show you these two tables,their fields and there relations.
























Now the below  job will insert the invoiceheader with calculated totals and 2 lines. Note, that there is no place where recid is mentioned in the code. Business data only.







































One thing that I need to mention there is that.In the above code I have write the code i.e "line.invoiceheader(header);"

This is the method use to link the invoiceline table and the parent table.To call this method we have to first set the property CreateNavigationPaneProperty to "Yes".As shown in the image below:



Now When I run this job an exception will occured as you can see in the below image.

























I have run a job due to this issue the exception is occured to resolve this issue I have to make a static method inside the class and also include server tags in that method.as you can see in the below image.







Now when I call this method the data will be inserted successfully.you can see the below image of tables which contains the data that I have inserted.
 



 

 
 




































Thanks

Muhammad Zahid.

Saturday 1 December 2012

Links on Fields on Forms

When we open the form.There are some fields which are like hyperlinks and when we click on these
fields a new form is open.

As you can see the example below just go to the Account Receivable->Customers->All Customers.
The new form will open with fields cotaining the hyperlink.





And when I click on this field a new form is open as you can see in the below image.

 
 
 
Basically these fields physically exist in other table and they are showing on this table through foreign key.
 
The question is how the form is open when we click on these fields.The simple answer is that to open the form on this field just go to the table in which this field actually resides and than in the property of that table set the formref=formname.

Now The Query that shows the data on the Preview Pane is "CustListPagePreviewPane".In that Query there is table i.e custtable which uses that field i.e "CustGroup".Now we will go into the relation of that table to show that what is the parent table in which this field actually exist.

You can see the image of the custtable in the below image.























Now we will go to the property of the table CustGroup and see the FormRef propery.

















As you can see the name of the form in the formref property.This is the form which open when we click on the link custgroup.

Thanks

Muhammad Zahid.
 

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.