Wednesday 18 December 2013

Policy Framework in Dynamics AX 2012


Policy Framework:


The policy framework can be used to enforce rules for the Microsoft Dynamics AX 2012 users to help improve the business process. Below are the three key components of the robust policy framework in AX 2012.
  1. Policy Types.
  2. Rule types.
  3. Policy rules.

Policy Types:


A Policy type is a collection of all the rule types that are applicable to a given module or feature area.
 
A user in a manager role can be granted permission to define policies of a given type through a menu item that opens a list page.The list page displays all the policies of a particular policy type.
 
Microsoft Dynamics AX 2012 ships with six policy types.These types are specified with the following SysPolicyTypeEnum enumeration values:
 
  1.  Approval Policy.
  2.  Audit Policy.
  3.  Purchasing Policy.
  4.  TrvExpensePolicy.
  5.  TrvRequisitionPolicy.
  6.  VendInvoicesPolicy.

Rule Types:


Each Policy type encompasses an entire feature area;its associated rule types categorize the rule that can be set up for specifix features within that area.For example,airline,hotel,and meals are examples of expense policy rule types.
 
Each Policy type can have any number of related rule types.
 
Unlike policy types,which are static and well known,rule types do  not have to predefined(although they generally  are).For example,the AuditPolicy and VendorInvoicePolicy policy types allow the user to define the rule types that are to be enforced.Rule types for these two policy types do not ship with Microsoft Dynamics AX 2012.All othe types have a predefined set of rule types that do ship with Microsoft Dynamics AX 2012.

Note:Audit Policy Type and Vendor Invoice Policy Type dont have predefine rule type they allow the user to create their own rule type while the other policy types have predefine rule types.

Policy Rules:


Policy rules is basically that kind which holds the data based on that policy will become active or inactive.the best example for this is such a limit can be that the employees can incur a maximum of $1500of airlines for their travel and if their expense exceeds the limit than they have to provide the justification.

Creating a Policy Type:


To create a new policy type,complete the following steps
 
1. Add a new value for the policy type to the SysPolicyTypeEnum base enumeration.
 
2.Create a row for the new policy type in the SysPolicyType table.
 
To create a row for the new policy type in the SysPolicyType table there is simple easy step

Create a new method in SysPolicySetupClass like the below:

private void loadzahid532policy()
{
SysPolicyType policyType = SysPolicySetup::addPolicyType(SysPolicyTypeEnum::zahidpolicy532,HierarchyPurpose::ExpenseControl);
}
 
 
In the above code the HierarchyPurpose shows the purpose of  policy on behalf of that the policy will  open and zahidpolicy123 is the name of the enum that we have created in the step one.

Now call this above newly created method from the loaddata() method of that class i,e SysPolicySetupClass.
 
Now write a simple job to load that policy into the SysPolicyType table as given below.

static void Job1(Ards _args)
{

SysPolicySetup obj=new SysPolicySetup();
obj.loadData();
info("done");

}

Now after running the job the policy will be  inserted into the SysPolicyType table.

Now to open the Policy form you have to create the display type menu item.
 
In that menu item you have to set some properties:
 
Set ObjectType=Form
 
Object=SysPolicyListPage
 
EnumTypeParameter=SysPolicyTypeEnum.
 
Enum Parameter=name of the enum that you have created in the SyspolicyTypeEnum in step 1
 
Paramters=Enum value of the above enum that you have created in step 1.
 
Below are the screen shots of my menu item properties and the enum properties:
 
 
 
 
 
 
 
Now open that newly created menu item and the Polic form will open like the given below:
 
 


Now click on the new policy button as you can see the button in the above image.

when you click the button the new policy creation form will open like this given below:


note:When you open the above form the warning message will appear like the given below:

 
 
To remove this warning when opening the form just click on the parameter button as you can see in the second last image.The new form will open like given below:
 
 




Now select the Companies from Organizational types and than click on the add button and than close the form.
Now the warning will not appear.

Now as you can see in the third last image that there are no rule types are shown.This is because we have not created the rule types.Now we will create the rule types.

Creating a Rule Type:


Now add the below line of code in the method loadzahid532policy() that we have created above in the previous steps.
 
SusPolicySetup::addRuleType(policytype,SysPolicyRuleTypeEnum::TrvAirlinePolicyRule,formStr(TrvPolicyRule));
 
The above code will add the rule i.e TrvAirlinePolicyRule in our new created policy.
 
 Now again run the job again that we have created in the previous steps.
 
 Now rule type is added in our policy as you can see in the below image:
 
 

 
 Microsoft Dynamics ax ships with many rule types.You can create many rule types as you want in a single Policy.
 
Now the next step is creating Policy Rule.
 

Creating Policy Rule:


Now click on  Airline and than click on the CreatePolicyrule button as you can see in the above image.

An exception will generate as you can see in the below image.

This exception has taken my 2 days to fix :( :(



 
 
 
The scene is that when we click the button i,e create policy rule.A new form i.e TrvPolicyRule
is open.
 
Inside the init method of that form there are several switch cases present as you can see inside the init method of  the form TrvPolicyRule.
 
Basically these switch cases are checking from which syspolicytype enum these form is called and than setting the data according  to them.
 
In our case we have created our new type enum and the swich case of our newly created type is not present in the code therefore it was throwing an exception.  
 
Note:Only in case of travel expense and travel requisition we need to insert the cases.
 
As you know i am implementing travel expense policy therefore i will add the switch case for
setting the travel expense below is the screen shot available:
 
 
 
 Now again click on the button create policy rule.as you can see in the image below.


 
 after clicking the form a new form will open as you can see in the below image.































Now the above form is for creating the policy rule for the Airline expense.

I have created the rule that if the user expense is greater than  1000 than he has to enter the justification why his expense increases the limit.

 
Now press the ok button.Your Policy is created successfully.

Note that the policy needs to be active to take effect.

Now you can see in the below image that how this policy works when the user goes into the Employee self-service portal and creates his expense report for the airlines expenses and tries to submit it.

















Now you can see in the above image that the policy framework’s warning icon gets activated which we have setup back in the expense policy for airlines. just because of his expense has exceeds the limit that we have set. He will now have to go to the expense line again and enter a justification for this expense exceeding maximum allowed amount, for him to be able to submit the expense report.

As you can see in the below image.

 
The Microsoft Dynamics AX 2012’s policy framework is flexible enough to define any number of very simple to complex audit policies across your organization under the Expense Management, Vendor invoices, purchase orders etc. areas, there by allowing your admin staff and reviewers focus on their day-to-day work more, rather than spending time in evaluating business processes violations manually.
 
 
Thanks :) :) :)


No comments:

Post a Comment

SQL/SSRS Interview questions I thought of blogging some SQL/SSRS interview questions.

Below are some. I will add more, when I complete the compilation 1. What is OLTP(Online Transaction Processing)? OLTP stands ...