Archive

Author Archive

Security Framework in Microsoft Dynamics AX 2012 – Part One

July 9th, 2012 Khushhal Garg No comments

Today, I am going to focus on the new security framework in Microsoft Dynamics AX 2012. Microsoft Dynamics AX 2012 has a new security framework based on role-based security. In Dynamics AX 2009, it was hard to setup security without a developer, but in Dynamics AX 2012 a system administrator can setup security roles with very little help required from developers. In case data level security is required, developer help is required to create XDS policies, which is a new concept in Dynamics AX 2012. But once XDS policies are created by a developer, an administrator can manage security and assign users to security roles.

In Part I of today’s topic, I will cover the Security Model Overview.

Security Model Overview: The new security framework in Dynamics AX 2012 contains many new elements. Figure 1 contains all the elements that are part of it.

  • User groups no longer part of the security framework.
  • Security roles, duties, privileges are new elements used in security framework.
  • Domains are replaced with Organizations.
  • Companies are replaced with Legal Entities.
  • Security keys are no longer used.
  • Flexible Authentication
    • External users can connect to Enterprise Portal without having an account in Active Directory.
    • Active Directory groups can be used as authentication type, which is a great help as a system administrator can control the access by Active Directory groups. If a user is removed from an Active Directory group that already has access to AX, the user will lose access to Dynamics AX without needing to do anything in Dynamics AX. Similarly, if a user is added in an Active Directory group that already has access to Dynamics AX, then the user will automatically get access to Dynamics AX without needing to add the user explicitly in Dynamics AX.
    • Roles are added directly to the groups similar to Active Directory users.
  • Hierarchical level security support is available.

Dynamics AX 2012 comes with over 80 security roles, which is a great help. These can be used as a starting point to setup security. New security roles, duties and privileges can be created based on business requirements.

Permissions can be set on user interface elements, tables and fields, SSRS reports, service operation securable objects.

Extensible data security (XDS) is a new concept added in the Dynamics AX 2012 security framework to control data security. In Dynamics AX 2009, Record Level Security (RLS) used to control data security. Though RLS exists in Dynamics AX 2012, it is not recommended to be used as it will be deprecated in the next release. I will cover it in more detail in future blogs on the Dynamics AX 2012 security framework.

Security Model Overview

Figure 1: The new security framework in Microsoft Dynamics AX 2012 contains many new elements, such as user authentication and authorization; security roles, duties, permissions; hierarchical level security support; etc

List of definitions for technical terms used in regards to Microsoft Dynamics AX

Figure 2: Here is a list of definitions for technical terms used in regards to Microsoft Dynamics AX

Stay tuned for Part II to cover more on the Microsoft Dynamics AX 2012 security framework. In the meantime, if you have any questions about Microsoft Dynamics AX 2012, please email us at dynamics@ignify.com.

Khushhal Garg is a Technical Manager of Microsoft Dynamics AX at Ignify. Ignify is a leading provider of Microsoft Dynamics ERP solutions to mid-market and Enterprise businesses. Ignify has been ranked as Microsoft Partner of the Year Winner in 2011 and 2010, and in the Microsoft Dynamics Inner Circle, Microsoft Dynamics Presidents Club in 2009. Ignify has offices and team members in Southern California, Northern California, Arizona, Tennessee, Illinois, Washington, Canada, Singapore, Malaysia, India, Philippines, and Jakarta.

Event Handling in Microsoft Dynamics AX 2012

June 21st, 2012 Khushhal Garg No comments

Today, I am going to talk on the event handling mechanism in Microsoft Dynamics AX 2012. With the event-handling mechanism in Microsoft Dynamics AX 2012 you can lower the cost of doing development and then upgrading these customizations.

Events are a simple and yet powerful concept. In daily life, we encounter with so many events. Events can be used to support these programming paradigms.

  • Observation: Generate alerts to see exceptional behavior.
  • Information dissemination: To convey information to right people at right time.
  • Decoupling: The consumer doesn’t need to know about the producer. Producer and Consumer can be sitting in totally different applications.
  • Terminology: Microsoft Dynamics AX 2012 events are based on .NET eventing concepts.
  •  
  • Producer: Object to trigger the event.
  • Consumer: Object to consume the event and process logic based on the event triggered.
  • Event: An action that needs to be triggered
  • Event Payload: Information that can go along with event.
  • Delegate: Definition that is passed to trigger an event. Basically, communicator between producer and consumer

Things to remember while using Events in AX2012

  • Delegate keyword to use in delegate method.
  • Public or any other accessibility specifier is not allowed in a delegate method.
  • Delegate Method return type must be void.
  • Delegate Method body must be empty.
  • A delegate declaration can have the same type of parameters as a method.
  • Event handlers can run only on the same tier as the publisher class of the delegate runs on.
  • Only static methods are allowed to be event handlers.
  • Delegate method can’t be called outside class. Basically, events can’t be raised outside class in which event is defined.
  • Event handlers for host methods can use one of two parameter signatures:
    • One parameter of the type XppPrePostArgs. Go through all the methods available in XppPrePostArgs.
    • The same parameters that are on the host method that the event handler subscribes to.

Now, let’s talk about how to use events in Microsoft Dynamics AX 2012.

  1. Let’s create a class Consumer to create EventHandler (sendEmailToCustomer). This will be called once order is shipped so that email can be sent to customer to notify. It has to be static method.

  2. Now let’s create Producer class where this event (sendEmailToCustomer) is called using Delegates. Add delegate by right clicking on Producer class > New > Delegate.

  3. Change its name to delegateEmail (you can have any name). Parameter should be same as event handler method (sendEmailToCustomer) i.e. of type Email. Notice it has no body and is a blank method.

  4. Now drag and drop sendEmailToCustomer method from Consumer class to delegateEmail

  5. Look at properties of EventHandler. You will notice it is pointing to Class Consumer and method sendEmailToCustomer

  6. If order is not shipped, I am creating another event handler (errorLog) in Consumer class to log error into error log.

  7. Create another delegate method (delegateErrorLog) in Producer class to call this event handler (errorLog)

  8. Drag and drop event handler (errorLog) in delegate method (delegateErrorLog) similar to step 4.
  9. Now let’s create main method in Producer class to ship order and let’s see how delegates can be used to trigger event handlers.

  10. Suppose shipOrder method returns true. Now, if I run this main method, it should go into delegateEmail method and should trigger method sendEmailToCustomer. Let’s run and see the result.
  11. Here is the result and it is as expected so it did trigger method sendEmailToCustomer.

  12. Let’s suppose shipOrder method returns false. Now, if I run this main method, it should go into delegateErrorLog method and should trigger method errorLog. Let’s run and see the result.

  13. Here is the result and it is as expected so it did trigger method errorLog.

  14. Handlers can also be added or removed

    Add Handler: It uses += sign.

    Remove Handler: It uses -= sign.

  15. Now, let’s use addStaticHandler in main method. If you see the code, it is calling addStaticHandler before calling delegate method. If we run it and see the result, it should send 2 emails.

  16. Here is the result as expected.

  17. Similarly if we use removeStaticHandler method instead of addStaticHandler before calling delegate method then it will remove handler and will not send any email.

So, you can see that with the use of delegates and event handlers, it is so easy to trigger events. Also, it will be easy and less time consuming to upgrade it. Suppose if delegates are called from standard methods while doing customizations then it will be so easy to upgrade if standard methods are changed in next release because only 1 liner code of calling delegate method needs to be rearranged and no changes will be required in event handler methods.

Use of Pre and Post event handlers

In Microsoft Dynamics AX 2012, any event handler method can dropped in other method. If the property "CalledWhen" is set to "Pre" then it becomes pre event handler. If it is set to "Post" then it becomes post event handler. Pre event handler is called before the method under which it is dropped and Post event handler is called after method ends. These are so powerful that event handler method can be created in new class and can be dropped in any standard or any other method without changing a single line of code and can be set as pre or post event handler as per business need. Suppose, before creating a customer in AX, business need is to do some business logic then logic can be written in pre event handler and can be dropped in insert method of CustTable. Similarly, if there is post logic to be written after customer is created then post event handler can be created and dropped in insert method of the Customer Table (CustTable).

Let’s see how pre and post event handler methods can be created and used.

  1. Let’s take same example. I added 2 event handler methods in Consumer class.

  2. Drag and drop both these event handlers in method sendEmailToCustomer

  3. Set property "CalledWhen" to Pre for EventHandler1 and Post for EventHandler2.

  4. Now let’s run main method of Producer class again and see the results. It should call EventHandler1 and then sendEmailToCustomer and then EventHandler2.

  5. Here is the result as expected.

With use of events, it has opened so many doors and possibilities. Model architecture and events can be integrated which can help if multiple vendors are doing customizations in different models so that it doesn’t impact customizations of other models/vendors. Use of pre and post handlers is so powerful that it can be used without changing a single line of code in original method. Pre or Post handlers can be just dropped in the original method and will be called automatically before (pre handler method) or after (post handler method) original method.

Stay tuned for more technical tips on Microsoft Dynamics AX 2012.

Khushhal Garg is a Technical Manager of Microsoft Dynamics AX at Ignify. Ignify is a leading provider of Microsoft Dynamics ERP solutions to mid-market and Enterprise businesses. Ignify has been ranked as Microsoft Partner of the Year Winner in 2011 and 2010 and in the Microsoft Dynamics Inner Circle, Microsoft Dynamics Presidents Club in 2009. Ignify has offices and team members in Southern California, Northern California, Arizona, Tennessee, Illinois, Washington, Canada, Singapore, Malaysia, India, Philippines.

Dynamics AX Tips and Tricks from past implementations – I

November 23rd, 2009 Khushhal Garg 3 comments

We recently started Dyanmics AX community discussion meetings to internally talk about projects – what worked,  what didn't to share our learnings and strengthen our practice. On Nov 21, 2009, we held our first DAX community meeting in Los Angeles. The idea of this meeting is to contribute new learning, knowledge sharing, sharing solution designs towards DAX community.  We took one project which went live last month and discussed the implementation cycle.

 

We discussed major features of this project like Warehouse Management, Auction Upload, Bidding, Inventory Reservation, Order Creation, Picking, Shipping, Invoicing, Returns, Order Cancellation, Refunds, Coupon Management. This involves integration of Dynamics AX with front end. Front end is implemented in Java and integration is done using .net business connector.

 

We also discussed what gotchas we faced during this project implementation and what pain points business was having. Initially, we faced integration problem. For example, one of the challenges was around doing integration between Java applications and Dynamics AX?   we created a .net dll that uses the .net business connector to connect to AX and Java in turn is calling this dll.

 

Before this implementation, the customer was using a legacy system which was implemented in .net and SQL. The in-house system did not provide ERP features and Warehouse Management functionality. For example – the system did not have proper order cancellation and customer refund processes. A significant advantage that the customer got from new implementation is the robust ERP system with a full-fledged warehouse management system, order cancellation and customer refund process. It is so easy now for the users to calculate accurate refund using Dynamics AX standard RMA creation process. We enhanced the standard RMA process a little bit but the basic process is very much standard AX. Claim process is also utilizing RMA functionality. The only difference between RMA and Claim process is that item doesn’t get received back in Claim process. We also customized it to give user facility to adjust sales/refunds.

 

We also implemented a rule engine which monitors the order while creation and puts the order into Not Reviewed, Suspect, Stopped, Released state based on fraud rules setup.

 

There is a new requirement to have the customer cash credit feature within AX. The requirement is that customer can refer other customer and customer who referred should get cash credit based on first purchase done by customer whom customer referred. Basically, to have referral reward feature within AX. We discussed design solution to implement this requirement and we come up with 2 design solution. One to use standard free text invoice and second to use standard payment journal feature of AX. Most probably, we will go with payment journal feature.

 

More to come!

 

This post is written by Khushhal Garg. Attendees at the Dynamics AX community meeting were Khushhal Garg, Craig Griffith, Ravinder Singh, Gopi Balakrishnan and Satish Panwar. Khushhal Garg is a Dynamics AX technical manager in the Microsoft Dynamics AX Practice at Ignify . Ignify is a Global Microsoft Dynamics Inner Circle Partner specializing in Dynamics AX for Retail, Distribution, Manufacturing and Chemicals verticals. For help on Microsoft Dynamics ERP email us at dynamics@ignify.com.

Using “Intertable” Relations in Dynamics AX

November 9th, 2009 Khushhal Garg No comments

In Dynamics AX, development team members use QueryBuildDataSource and QueryBuildRange class fairly frequently. These make it easy to apply relations between different tables and apply ranges on data source. But many developers are not familiar with intertable relations. These allow you to apply an range within the same table on different columns and relate columns within the same table. Here is a code example of the use of an Intertable relations in Dynamics AX

Query q = new Query(); // Initialize query
QueryBuildDataSource qbdsTableA; // Declare variables 
// Add datasource TableA
// Add Range on field1 and TableA.field1 should be greater than TableA.field2
; qbdsTableA= q.addDataSource(tablenum(TableA)); 
qbdsTableA.addRange(fieldNum(TableA,Field1))
    .value(strFmt("%1 > %2" fieldStr(TableA,Field1),fieldStr(TableA,Field2)));