Set a default entity on a lookup window

In case you have more entities to chose from on a lookup window, then you might want to be able to set the default for this lookup. For instance, the regarding field on an activity entity like letter, email and fax does support multiple entities. If you want this to default set to contact, then use this javascript on the form onload:


//set default
crmForm.all.regardingobjectid.defaulttype = "2";


Even better, what if you dont want your user to be able to choose any entity and force them to use the contact entity? Then use this script:


//set only contact
crmForm.all.regardingobjectid.lookuptypes = "2";

//set icon
crmForm.all.regardingobjectid.lookuptypeIcons = "/_imgs/ico_16_2.gif";


Dont forget to set the icon. The icon will be displayed in front of the selected name after a selection in the lookup box has been made.

For a custom entity, then mind that the icon does not work that easily. Use this script for custom entities:


//set only contact
crmForm.all.regardingobjectid.lookuptypes = "10003";

//set icon
crmForm.all.regardingobjectid.lookuptypeIcons = "/_imgs/icon.aspx?objectTypeCode=10003&iconType=GridIcon&inProduction=1&cache=1";


Good luck!

9 comments:

Dutch CRM guy said...

Hi Ronald,

Great tip! I have an addissional question. Is is possible to manipulate the lookup window so that you will only see the related records.

For example I want to choose the primairy contact on the Account screen. When I choose the lookup button you get the complete contact set. I only want to see the contacts who are related to this specific Account.

Thanks,

Jean-paul

Ronald Lemmen said...

Hi Jean-Paul,

I haven't found any solution to that yet. If you find any, please let me know!

Ronald

Ronald Lemmen said...

Jean-Paul,

I've just posted a new post which you need to fix your issue. Here's the link:
http://ronaldlemmen.blogspot.com/2006/12/filter-data-in-crm-lookup-field.html

Anonymous said...

I did more or less the same, but directly in the xml of the entity (export, modify, import). Just where the fields are defined (FieldXml>) Examples for the appointment entity:

field name="requiredattendees" requiredlevel="required" lookupclass="ActivityRecipient" lookupstyle="multi" lookuptypes="2" lookupbrowse="0"

and

field name="optionalattendees" requiredlevel="required" lookupclass="ActivityRecipient" lookupstyle="single" lookuptypes="1" lookupbrowse="0"

I do not now if this is and will be supported, but it works fine.

Anonymous said...

Nice trick. I've used the script (with modifications, of course) to constraint the lookup values based not on a crmForm.objectid value, but the value of different lookup that is included on the same form.

So, in this way you can manage circular references - if the first lookup (LKP1) refers to an entity that is parental to the entity that is referred by the second lookup (LKP2), you can constraint the values for the LKP2 based on the value of LKP1. That's exactly what I was looking for, so thanks for the hint.

Anonymous said...

Hi Ronald,

Would it be possible to assign a specific default value from a lookup field through the onload event?

Ex. On every new contact created, I would want the default value of the owner to be set to my customer service rep instead of the current user.

Anonymous said...

Hello Ronald

Excellent work. I set up the lookup field you shown. It comes out to be pretty good but when I save and open the record the name in the LookUp field is missing and left with Icon only.

Any suggestion for me.

Thanks in Advance.
Kind Regards

Anonymous said...

That's great Ronald. But can you tell me where you would put in this javascript, if I'm trying to set the Lookup records for the Account & Contact lookup to default to Contact.

Should I be going to \_controls/lookup/lookupsingle.aspx?

Ronald Lemmen said...

Hi Gerald,

You should place this code in the form onload of the entity form on which the lookup is placed.

Kind regards,
Ronald