Udostępnij za pośrednictwem


Microsoft Dynamics CRM 4.0 Tidbits - Advanced Events

I Walk The Line...

With CRM 3.0 we had a pretty robust model for building custom business logic extensions, known as callouts, which allowed developers to write C# or VB.NET code to handle pre-stage and post-stage events for platform operations such as:

  • Create
  • Update
  • Delete
  • ChangeState
  • Merge
  • Assign

However, this list of events is far from complete. In CRM 4.0 not only do we have a new event architecture (as described in my earlier post here), but we have many more events available, including:

  • Query
  • QueryMultiple

Now it might not seem obvious at first glance, but these two events are possibly the most useful addition to the new CRM platform. Why? Well almost every time you access a page in CRM, that page instructs the CRM platform to execute a Query (for example when you open the account entity form) or a QueryMultiple (if viewing a list of accounts in the grid view). Now with the CRM 4.0 event architecture, not only do we have the ability to run custom business logic to handle 'Query' and 'QueryMultiple' events but we can actually modify the query itself during the pre-stage event, or modify the results during the post-stage event.

To illustrate this I wanted to build a plug-in to solve a problem that many customers have come across. Queues are containers that hold activities and incidents (cases). They make it easier for these entities to be moved around the system, handled and assigned to different individuals within the system and form the basis of many case management solutions used by customers. Unfortunately, because the queue entity is organisational-owned (as opposed to user-owned), all queues are visible to all users if they are a member of any security role with the queue READ access right. Some customers have large numbers of queues, making it very difficult for users to navigate the list.

A common customer request is to have some way of filtering this list, only displaying queues that are relevant to a particular user. Unfortunately, the queue design in CRM 4.0 hasn't changed significantly from CRM 3.0, but building a plug-in to handle the pre-stage 'QueryMultiple' event on the queue entity, I was able to modify the query to filter the list. In this case, my code only displays queues that are associated with the same business unit as the user, but you could implement almost any filter you chose using this method.

Rather than bore you with a line-by-line review of the code, I have zipped up the Visual Studio 2005 project and added it as an attachment to this post here. However, just to whet your appetite, here are a couple of screenshots of the queue view when logged in as two different users.

Queue View Logged in as CRM Admin

Queue View For CRM Admin

Queue View Logged in as Alan Jackson

Queue View For Alan Jackson

I would just add one word of caution. This event will fire each time a user navigates to the queue view page, so you must ensure that your code is a efficient as possible, otherwise you could introduce signficant performance and scalability issues. As the proverb says: "With great power comes great responsibility".

This posting is provided "AS IS" with no warranties, and confers no rights.

Laughing Boy

CRM.PlugIn.zip

Comments

  • Anonymous
    October 09, 2007
    PingBack from http://business.wpbloggers.com/?p=1520

  • Anonymous
    October 15, 2007
    White Wedding... To make sure I didn't duplicate any information in my blog, I have been compiling a

  • Anonymous
    January 22, 2008
    Hi, it sounds great and it realy works for Queue. Unfortunately pre-stage 'RetrieveMultiple' haven't fired for Accounts and Contacts and I don't know about others. Could you help me to find the reason why it doesn't work? Thanks a lot.

  • Anonymous
    January 22, 2008
    Alena, perhaps you could provide more information on the problem, otherwise there isn't much to go on. Regards, Simon

  • Anonymous
    May 02, 2008
    Quite common I get questions regarding modifications on queues. What can be changed in the main GUI and

  • Anonymous
    June 08, 2008
    The comment has been removed

  • Anonymous
    October 28, 2008
    Quite common I get questions regarding modifications on queues. What can be changed in the main GUI and

  • Anonymous
    September 13, 2010
    Hi Simon, I am a newbie to CRM and I am trying to get this code to work. I am getting an error in the  foreach loop for the ConditionExpression after it loops through attributenames 'primaryuserid' and 'queuetypecode'. I have no idea what's going wrong for me. Please let me know if you have any suggestions. Any help is greatly appreciated. Thanks!! Raj.

  • Anonymous
    December 06, 2010
    Hi Can you explain the procedure to register this plugin? I need the same funcionality (users only can view queues related to their BU) Thanks