Thursday 6 December 2012

Unit Of Work Implementation in Dynamics AX


UNIT OF WORK:

Unit of work keeps track of everything you do during a transaction that can effect the database. It keeps track of everything that needs to be done to alter the database as a result of your work.

There is a system class called UnitOfWork Class in X++ that implements the Unit Of Work Framework. Some of it's details are given below.

Clear
 Clears all the changes
DeleteonSaveChanges
 Deletes the record on commit/save changes
InsertOnSaveChanges
 Inserts the record on commit /save changes
UpdateOnSaveChanges
 Updates the record on commit /save changes
SaveChanges
 Save the changes on the server

Implementing the Unit Of Work:

In this example we will perform bulk insertion on tables , this is where the role of Unit of work comes into play . By means of it we can insert lines against a header record without creating the header first on the basis of the Rec Id that comes as a foreign key in the child table.

Example:


In this example you can see we have created two tables :
  • Candidate 
  • Exam
Where the Exam table behaves as the header table and the Candidate tables acts as the Lines.The Screen shot below shows the relation between them.


After this step we need to set the CreateNavigationPropertyMethods Property to Yes.  As Shown in the screen shot below.


After that we need to create a new class and add a Method in it that will perform all the calculations and insertions , as shown in the screen shot below.



 Finally we need to call this method in a job. The results can be seen by opening the tables.



In this way the DataSources can be grouped as a unit of work and Ax Client has great support for it.

I believe it was helpful.  


Tuesday 4 December 2012

Work Flow in Dynamics Ax 2012


WORKFLOW:


A Work Flow can be defined as a sequence of steps where each steps follows the precedent without any gap or delay.It can also be defined as a movement of tasks within a process. The Dynamics AX Work Flow infrastructure enables user configurable workflows in Dynamics Ax application modules with specific focus on tasks and approval workflows.



A Work Flow is designed based on the company requirements then Configured by the administrator , and run by the user.

BASIC CONCEPTS:

Work Flow Type:

It is the basic building block that can be used to create customized workflows that enforce business policies. A Work Flow type defines :
  • The Work Flow document to use.
  • Tasks and approvals that can be configured by the User.
  • Workflow categories used to assign a workflow type to a specific module.
  • Menu item and Event Handlers to be used.

Work Flow Configurations:

These are created by the application administrators that use Dynamics Ax Work Flow editor. The administrator configures the:
  • Work Flow
  • Workflow Elements.
  • Approval elements to control the flow of business document through workflow process.

Work Flow Instances:

Created by the Work Flow run time when the workflow is activated.

Work Flow Elements:

These are created in the AOT and configured by the administrator. A Work Flow structure consists of a sequence of Work Flow elements that includes:
  • Tasks
  • Approval
  • Sub-Work Flow

Developer's Role:

A Developer adds Work Flow to an existing business document or Creates new document that support Work Flow. A developer performs these steps :
  • Creates a Query for Work Flow.
  • Creates a Work Flow Category.
  • Creates a Work Flow Type.
  • Creates Work Flow elements.
  • Enables Work Flow on a Form.

Creating Query For Work Flow:

An AOT Query can be simply created under the Queries node in AOT. Right click on the queries node and  Create New Query.


for further information on queries see  here

Creating Work Flow Category:

Expand the Work Flow node and right click on the Work Flow categories node to create a new Category.


In the Property Sheet for the newly created module set it's name and module properties.

Creating Work Flow Type:

To create Work Flow type we need to run a Workflow Type wizard.
AOT--> Work Flows--> Work Flow Type  right click and then go to addins and run Work Flow Type wizard.


Create Work Flow Elements:

To Create Work Flow elements we have multiple ways . For (e.g) In order to create an Approval Element for the workflow we can run an Approval wizard as shown below.


Or you can create tasks by these steps:
AOT--> Work Flow-->Tasks-->New Task

Enabling Work Flow on a Form:

Expand the form , expand it's designs node and on the design node right click properties. On the Properties window set the following properties:

Work Flow Enabled       :        ( Yes ) 
Work Flow Data Source:        (Data Source for the Query)
Work Flow Type            :        (Work Flow Type Created)