 |
|
 |
Assigning default values to lookup fields
Category: Extending MS CRM | Posted on Wednesday, May 14, 2008
This solution works the same way on both MS CRM 3.0 and 4.0.
1. Open up your MS CRM in a browser.
2. Navigate to the entity you like to link to as a default value in your lookup field.
3. Click Ctrl + N to open up a new browser window showing the entity with its 32 digits plus 4 dashes Guid in the browsers address field. The Guid is the unique id of the entity.

4. Write down the Guid or save it to your clipboard.
5. You also need to know the name, type and typename of the entity you are linking to and also the attribute name of the lookup field you are assigning the value to.
6. Copy the below script to the onLoad event of the form that holds the lookup filed.
7. Remember to enable the script and publish the entity.
if(crmForm.FormType == 1)
{
var newlookup = new Array(new Object());
newlookup [0].id = "{ replace this with the Guid of the entity }";
newlookup [0].name = "replace this with the name of the entity";
newlookup [0].type = replace with type number of the entity your are linking to;
newlookup [0].typename = "replace with typename of the entity your are linking to";
crmForm.all.< replace with lookup attribute name >.AddItems(newlookup);
}
|
How the final result might look like.

As you can see it’s not that hard to do and it can save lots of users much time filling out forms.
|
|
All source code on this website is provided as is. If you use any of my solutions or just parts of them I’m not to be held responsible for any errors or loss of data you might encounter.
|
|