Friday, September 14, 2007

Set Regarding Lookup Default Entity

I've had numerous customers request, that in order to help their best practices, that the default object on the Regarding field default to the entity users should be associating activities. Some clients want it to default to Contact, others to Opportunities, and some to custom objects. I could never figure out how to get control of the window or form assistant where the entity dropdown list is made available. However, one of my co-workers found that we don't need control of the window, we can set the default attribute with a bit of JScript.

On the OnLoad event of the activity (theoretically this should work for whatever lookup you want, i.e. the Customer field on Case and Opportunity) place the following script:

if (crmForm.all.regardingobjectid != null) {
    crmForm.all.regardingobjectid.setAttribute("defaulttype", "2");
}

This code will set the default entity to be Contact. If you want a custom object they start at 10000. So, just fine the ObjectTypeCode of the entity you want (that can have activities associated to them) and place them in the quotes as the second parameter of the setAttribute method and you're set.

Please note that this only effects the window that gets opened when you click on the magnifying glass of the Regarding field. However it does not effect the Form Assistant. So, this doesn't do it all, but it does help in some regard.

Also, please note that this customization is not supported by the SDK and may be subject to change in the next version. But while this is a "lighter" unsupported customization it's the kind of customization that I like. No files get modified, upgrade path does not get hindered, you just have to check it after the upgrade to make sure it works. If it doesn't, you have to find the new method or call that is used to do what we just did.

Short, simple and sweet. Happy coding!

David Fronk
Dynamic Methods Inc.

2 comments:

cc sue said...

How would you reset the regarding object when tracking an email FROM Outlook?

Dynamic Methods said...

CC Sue,

If you are using MSCRM 4.0 you should be able to just change the regarding from Outlook. If I remember correctly in MSCRM 3.0 this was not so easy. I am assuming that you have set the regarding for an email but want to change it to something else.

If you are talking about performing this customization for when users click on "Set Regarding" from Outlook I'm afraid I haven't ever done anything with that. You could try this code and apply it to the regarding field on an email form and see if that works. However, my gut tells me that it won't work since the script would be on the onLoad of the Email form, which wouldn't get loaded from your main Outlook page.

If you are looking to just reset what the regarding is set to, again 4.0 should just let you do it, 3.0 however I think you had to change it in the web form, but even then it wasn't 100% success because most emails are completed in CRM and you cannot update them.

Good luck,

David Fronk
Dynamic Methods Inc.

Post a Comment