Lookups Against Closed Records
In a recent post I included a thread between Bob Haverty and me regarding a question he’d emailed me and to which I didn’t have a good answer. I tweeted about it, included a link to the post and encouraged readers to post comments if they had any ideas about or answers to Bob’s question. The next day, Jukka Niiranen
was generous enough to post a suggestion and a link to an article by Jim Wang that solved Bob’s problem. Thanks Jukka!
Here’s the article by Jim Wang: http://jianwang.blogspot.com/2009/04/show-both-active-and-inactive-records.html
Here’s the URL of Jukka’s blog: http://niiranen.eu/crm/
This is actually a more general point than I thought at first. (Bob, next time you email me a question I’ll read it more carefully!) What it really has to do with is whether closed records show up in an entity’s Lookup view. By default they don’t, even though there’s no real reason they shouldn’t. You can see an example of this if you have an activity record – task, email, … take your pick – attached to an opportunity. If you close out the opportunity the activity record is still intact, and you can still see the opportunity record in the Regarding (lookup) field on the activity form. You can even click the link to the (now closed) opportunity record and navigate to its form, and verify that the record is closed. But I you tried to select the closed opportunity record from the lookup view, you can’t – closed records aren’t exposed there by default!
From a business standpoint there might be plenty of times when it’s appropriate to attach something like an email, phone call or a task to a closed record. What if you were sending an email to a colleague and wanted to make it regarding a previous opportunity that happened to be closed? Or how about if you were making a followup phone call regarding a case that had been resolved? By default, you can’t do any of these things, because closed records don’t show up in the lookup view.
To allow the attaching of an activity record to any closed record, all you have to do is customize the specific activity type (email, phone call, task, etc.), and add this code to the form load event:
crmForm.all.regardingobjectid.lookupclass = “alllookups”;
Here’s what the load event will look like if that’s all you have in there:

What does that “regardingobjectid” refer to? That’s simply the attribute name of the standard “Regarding” lookup field you see on every activity form in Dynamics CRM. You can see it here it is on the standard E-Mail form:

Since there’s only one “regardingobjectid” field, this will work no matter what kind of record type you want to attach the activity to! And remember, this means that after publishing these customizations, you will see a lot more records in your lookups than you did before…because now you see both active and inactive records! So, you might want to add the Status value to the Lookup views for important records. With the default settings that isn’t necessary since you won’t see any inactive records. But with the approach described here you’ll see all records and you might want to give your users the ability to distinguish between active and inactive ones. Here’s what my Regarding lookup view looks like now if I select the Opportunity entity, after I added Status to the Lookup view:




Peter Said,
August 24, 2009 @ 6:47 am
Thanks! Have you tried this for Disabled users? I don’t think it will work for ownerid, but it might for a custom user relationship.
Richard Knudson Said,
August 24, 2009 @ 6:50 am
Hi Peter —
Well, there’s always a little wrinkle, isn’t there?
Good suggestion. I haven’t tried that yet, but I will. Thanks!
Richard
Mark Said,
September 11, 2009 @ 3:21 pm
Richard, very cool post. I tried this for a custom entity related to a quote. I added the onload script you mentioned (with a different id of course) to the custom entity and it worked. The lookup includes all quotes, not just active ones.
Question: when looking at an inactive record, and clicking on the associated records in the left nav, the “add new” and “add existing” (for a N:N relationship at least) buttons are hidden in the associated list toolbar. Have you found a way to stop those buttons from hiding when a record is made inactive?
What I’m asking is sort of the reverse relationship for what you did above.
Thanks!
Cheri Beaucage Said,
February 11, 2011 @ 6:07 pm
Please let me know if you’re looking for a article author for your site. You have some really great posts and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine. Please send me an e-mail if interested. Thanks!
Richard Knudson Said,
February 12, 2011 @ 2:11 pm
Hi Cheri,
Thanks for the note. I like your idea — I’m always looking for good content. No reason it always has to be me writing it! I’ll send you an email.
Richard
Daniel Parkman Said,
October 7, 2011 @ 5:43 am
Hi Richard,
I have applied the code to the form load event for the task activity and published the changes however I am still only getting active records returned. In this instance, the entity I am looking up is a custom entity. Would this be the casue of it not working? Is there something that I am missing?
Your help would be much appreciated!
Regards
Daniel