Associate A Record To One of Two Entity Types (CRM 2011)
Here’s another old blog I’m republishing. This functionality is now native in CRM 2013 and CRM 2015 as Business rules. Sometimes, you want to one same entity and associate it to two other entity types. For example, you might have a License that could apply to either an Account or a Contact. You could create two entities – an “Account License” and a “Contact License,” or you could use this simple technique to use one entity that appears to be linked to a Contact or an Account. Here’s how: Create your new entity. On the Entity form, add three fields: A “Two Options” field called “Owned By,” and set option 0 to be Account and 1 to be Contact. Set the default to Account (1). A Lookup to a Contact called something like “Owner (Contact)” A Lookup to an Account called something like “Owner (Account)”. Create a new Web Resource with the following code: [code lang=”js”] function licenseOnLoad() { if (Xrm.Page.ui.getFormType() == 1) { ...