CRM 4 Multi Entity Type Lookup
Create a single lookup on a CRM form that allows the user to select from multiple entity types. Download these two entities to see this in action.

The code is a class that you can implement, so it really should be easy to use. To use the class do the following steps:
On the entity that requires the multi entity type lookup:
- Add a N:1 relationship for each entity type that you want in the lookup.

- Add the look ups to the form, add one where you want the Multi Entity Type and the others to tab that we will hide from the user.

- In the onload paste in the class at the top:
- Call the class to setup the lookup

- Call the onsave method

- Please let me know if you find this useful by posting a comment.
Labels: CRM4, JavaScript

11 Comments:
Hi,
Thank you, I have been looking for a solution to this problem for a while.
Just a quick question, 3 lookups to accounts on my form, so it is not the primary lookup I want to replace. So how would I do this? I take it I would not use the "PrimaryLookupFieldName" so what should I use instead?
Thanks again
P
22 February 2010 13:31
Hi P,
The code as it stands only works with distinct entity types, so you can't have two or three lookups to the same entity type, or account in you case.
PrimaryLookupFieldName is for reference only and you should not need to use it. The first lookup name passed into the class constructer is always the primary lookup field name.
One ore thing, this code will work account, contact and custom entity lookups, but many of the other system entities may not work. Your milage will very.
Sorry that's not much help with your problem. I assume your 3 lookups are mutually exclusive? Perhaps you could provide more detail on what you are trying to achieve, I'll try and help.
22 February 2010 19:57
Thanks for the reply.
At the moment I have a custom entity with various fields, 4 relevant N:1 relationship: my_Contact1, my_Contact2, my_Account1, my_Account2. I would like to have one lookup combined, eg Lookup1=(my_contact1) Lookup2(my_account1) and lookup3=(my_contact2, my_account2)
Where is it defined which lookup is passed first in to the class constructor? or am I missing the point completly?
I see that you have a N:1 system relationship called organization_sjackson_multientitytypelookup. Is this what is recognised at the first lookup? How was this relationship created?
Thanks for your help
P
23 February 2010 16:45
OK, so use the following constructor
var myMultiLookup = new C5CrmMultiEntityLookup('my_contact2','my_account2');
The class will then hide my_contact2 and create a temporary lookup in place that links to all the look ups.
The OnSave event, put's the value from the temporary lookup into the correct lookup and removes the temporary lookup.
I'm a bit confused why you have 4 lookups. If you just want a customer lookup from my_contact1 and my_account1, then my_contact2, my_account2 are not required.
var myMultiLookup = new C5CrmMultiEntityLookup('my_contact1','my_account1');
Does this help?
24 February 2010 05:51
Hi again, sorry about the delay in replying but I was on leave.
That worked great, I needed two multiLookups on one page so I used:
var myMultiLookup = new C5CrmMultiEntityLookup('my_contact1','my_account1');
var myMultiLookup2 = new C5CrmMultiEntityLookup('my_contact2','my_account2');
Thanks again for all your help
Regards
Peter
9 March 2010 16:12
Thanks for letting me know how you got on Peter. Glad I could help/
9 March 2010 19:43
Hi again, sorry I thought all was well but when the records are saved I am getting the following error:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Wed, 10 Mar 2010 11:56:42 UTC
Message: 'element.aoUnattachedEvents' is null or not an object
Line: 683
Char: 1
Code: 0
URI: http:// mydomain /_static/_forms/controls/img.lu.htc
Message: Object doesn't support this property or method
Line: 669
Char: 1
Code: 0
URI: http:// mydomain /_static/_forms/controls/form.crm.htc
Message: Object doesn't support this property or method
Line: 1
Char: 1
Code: 0
URI: http://mydomain/myinstance /userdefined/edit.aspx?id={DA096856-3B2C-DF11-A62F-0019B9E1F16D}&etc=10074
Message: Could not complete the operation due to error 80020101.
Line: 285
Char: 1
Code: 0
URI: http://mydomain/myinstance/userdefined/edit.aspx?id={DA096856-3B2C-DF11-A62F-0019B9E1F16D}&etc=10074
10 March 2010 12:06
Have you downloaded the example and tried that out.
Does that work without error? If not what Rollup do you have?
http://www.simonjackson.info/blog/attachments/customizations.zip
10 March 2010 12:13
Also, did you call the save method? Download the example example
10 March 2010 12:21
yes I am getting the same error with your sample files. Rollup 8
11 March 2010 09:39
opps, a bug seemed of made it into the code when I renamed the class. I've updated the example and the script on the original post.
12 March 2010 07:54
Post a Comment
Links to this post:
Create a Link
<< Home