Thursday, November 5, 2009

Add Related Entity Button on Form

Say you are a car lease company. As a CRM user you want an easy way to register a lease made by a contact. Every unnecessary click is one too many. You just want to check contact details and click ‘New Car Lease’.

New Carlease Button

Within the ISV config XML you can define custom buttons. All you need is the function that is used when a user clicks Car Leases –> New Car Lease. With some investigation you will find that the javascript function used looks something like:

locAddRelatedToNonForm(10006,2,'{5B20590A-37D0-DC11-AA32-0003FF33509E}', '')

Let’s take a closer look: “locAddRelatedToNonForm” is the function used, “10006” is the entitytypecode for car lease, “2” is the entitytypecode for contact, and “{5B20590A-37D0-DC11-AA32-0003FF33509E}” is the GUID of the specific contact that the function is called from. Looks like something we can reproduce for any record. Just need to replace the hardcoded numbers with the right variables.

This is where my last post, Retrieve EntityTypeCode on Entity Name, comes in handy. The first ETC needed is of the related entity. In my case the new entity is named ‘bd_carlease’. To  retrieve the ETC, use GetEntityTypeCode('bd_carlease')*.

The second one, for contact, is already available on the form, just use crmForm.ObjectTypeCode. And the GUID is also available with crmForm.ObjectId.

So all you need to do, is edit the ISV config XML like so:

<Entity name="contact">
    <ToolBar ValidForCreate="0" ValidForUpdate="1">
        <Button Icon="/_imgs/car16.gif" JavaScript="locAddRelatedToNonForm(GetEntityTypeCode('bd_carlease'), crmForm.ObjectTypeCode, crmForm.ObjectId, '');" Client="Web">
                <Title LCID="1033" Text="New Car Lease" />
                <ToolTip LCID="1033" Text="New Car Lease" />

And import it in MS CRM.

That’s all!

* make sure the you have the Retrieve EntityTypeCode funcions on the onload of the form.

1 comment:

  1. Find the latest used and new cars for sale.
    Great used car deals and prices.
    More here