Comment unsuccessful. Please correct the errors below.

Displaying inactive records in associated view

Associated views have always been a sore subject in CRM. When CRM 3 was released, they did not include inactive records and, despite the ever present Activate menu item, there was no any way to actually show all associated records not just active ones. People complained. Then rollup 2 changed the behaviour. People complained. Then there was a hotfix for custom entities. People complained that it should be available for system entities as well. CRM 4 is released and hotfix no longer works. People complain.

Plug-ins to the rescue

The good news is that CRM 4 plug-in model is flexible enough to solve this problem once and for all. The idea is to intercept RetrieveMultiple message and modify its query so that all associated records are returned. And the code is surprisingly simple:


  

using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;

namespace Acme.Plugins
{
    public class AssociatedViewPlugin : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            if (context.InputParameters.Contains(ParameterName.Query))
            {
                QueryExpression qe = context.InputParameters[ParameterName.Query] as QueryExpression;
                // If it's RetrieveMultiple multiple with two conditions
                if (qe.EntityName == context.PrimaryEntityName
                      && qe.Criteria != null
                      && qe.Criteria.Conditions != null
                      && qe.Criteria.Conditions.Count == 2)
                {
                    // If first condition is a statecode filter for inactive entities
                    ConditionExpression ce = qe.Criteria.Conditions[0] as ConditionExpression;
                    if (ce != null
                        && ce.AttributeName == "statecode"
                        && ce.Operator == ConditionOperator.Equal
                        && ((int)ce.Values[0]) == 0)
                    {
                        // Remove statecode filter
                        qe.Criteria.Conditions.Remove(ce);
                    }
                }
            }
        }
    }
}

Installation

  1. Compile the code and sign the assembly.
  2. Using Plug-in Registration Tool register the plug-in.
  3. Register execution step for the entity that you'd like to show all records in associated views. Note that we use PreStage (a.k.a. BeforeMainOperationOutsideTransaction) and Synchronous execution mode. For example, to always show inactive contacts in associated view:
    image
  4. Optionally add Status column to the associated view for the entity not to confuse users.
  5. Rinse and repeat 3-4 for other entities.

The result for the Contacts associated view inside account entity:

image

At long last Activate menu command makes sense.

Note: this code is a sample only and is included "AS IS" without any warranties whatsoever. In Real Life™ more stringent tests would have to be performed to ensure that RetrieveMultiple message indeed originated from the associated view and was not sent by your poor fellow co-worker complaining (or, worse still, raising support request with Microsoft) about filtering state code not working.

Posted by: George Doubinski
Last revised: 05 Dec, 2012 05:25 PM

Comments

10 Mar, 2008 11:25 AM

Just implemented this plugin and it works perfectly!

Thanks George!

June Brehm
June Brehm
09 Jun, 2014 05:18 AM

This information is very useful. Especially for us students. buy twitter followers

19 Sep, 2014 08:40 AM

Thanks for discussing your ideas with this blog. In addition, a Fantasy Regarding the banks Intentions while Talking About Foreclosure is that the Financial Institution will not Take My payments. situs sbobet There is a Certain Amount of time that the Bank will require payments from time to time . If you are far TOO deep Inside hole, they'll commonly demand that you Pay that Payment in full. However, I AM not saying that they will not Take any Sort of repayments at all. In the event you and the lender can manage to work some thing out, a Foreclosure Process May end. However, should you Continue to Miss payments in the new Strategy, the Home Foreclosure Process can pick up WHERE it was left off.

24 Dec, 2014 07:07 AM

Hi pal, that was a good post.

Humberto B. Peterman
Humberto B. Peterman
10 Mar, 2015 09:15 PM

Do you know what is the reason behind your low grades in essay assignments? If no then you should stay aware of what your class mates are doing. They are buying services from professionals and you also need to get custom essay if you wanted to get better grades in the class.

ram15
ram15
22 Apr, 2015 07:10 AM

The idea is to focus on facts and try and define a baseline problem to share. Best school in rewari

James Jane
James Jane
29 Dec, 2015 11:16 AM

You have shared great points to install this plugins registration and activation information. Its very useful plugin for checking records of students. UK interlocking horse mats

mike
mike
30 Dec, 2015 11:56 AM

You have posted very nice tutorial,i like reading it.Such tutorials are very helpful for students. grass mats

09 Feb, 2016 03:31 PM

This article is very good and useful for readers. thank you for sharing knowledge cara menggugurkan kandungan

12 Feb, 2016 12:26 PM

thanks for posting and sharing information through this very useful

Isabella
Isabella
01 Apr, 2016 09:22 AM

The number of institutes are doing the great work by engage the adults and the youth in studies and providing the positive parenting classes assignment help which is good for their mind growth and development of capabilities.

Jack Ryan
Jack Ryan
13 Apr, 2016 04:27 PM

Assembly language is low level language and that is close to the computer languages. That source code is quite helpful and the programmer can easily understand that bestessays piece of code and its functionality.

coper
coper
14 Apr, 2016 07:10 AM

Ray Ban sun shades action different Cheap Ray Ban administration and aswell effortless cool. Giving you the befalling to abrasion a cast in which looks air-conditioned contemporary and aswell appropriately elegant, Ray Ban eyewear is a accept to if you are austere about getting elegant. Whether you're analytic apropos simple and beautiful or conceivably ultra glamorous, Ray Ban can address to all tastes. As just about the a lot of accepted cast extensions apropos Ray Ban, the sunglasses ambit is accepted and in Oakley sunglasses outlet demand. If you're aggravating to acquisition affluence artisan sunglasses again Ray Ban could be the cast to buy.Another acumen to abrasion superior sunglasses would be to accord a adolescent analytic appearance. Keeping your appointment analytic younger, by the abridgement of furnishings from the sun can Cheap Ray Ban outlet accomplish you attending adolescent total.

24 Dec, 2016 09:10 AM

192.168.1.1 is the IP address that is commonly used by ADSL modems to configure and access to the router configuration panel.

20 Jan, 2017 10:10 AM

Be a Part of the No.1 Video Sharing Community. With VivaVideo, you can easily create professional-looking video stories within a few taps.

20 Jan, 2017 10:11 AM

Be a Part of the No.1 Video Sharing Community. With VivaVideo, you can easily create professional-looking video stories within a few taps.vivavideo 

henry
henry
22 Feb, 2017 04:47 PM

Great post you have shared with everyone, with great posting style. I am very happy to read your post, and must want to say bookmark this stuff for future updates. pay per call marketing

Your Comments

Comment unsuccessful. Please correct the errors below.
Used for your gravatar. Not required. Will not be public.
Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview