Add New Button on Lookup

Hi Guys,

I’ve been looking into how to enable the ‘new’ button on custom entities. Here is what I have found. O yeah, For the direct solution scroll to the end of the mail.

- You can set test some things when using this url:
http://localhost:5555/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=10001&browse=0&DefaultType=0&ShowNewButton=1&ShowPropButton=1
Ofcourse modify the servername and the objecttypes to match your situation

- The properties and new button can be set by using the querystring parameters as given above.

- There is one additional piece of hard coding in the class Microsoft.Crm.Web.Controls.Lookup.LookupPageBase. This particular piece of code is this:


if (this._showNewButton)
{
for (int j = 0; j < this._objectTypes.Length; j++)
{
switch (int.Parse(this._objectTypes[j], CultureInfo.InvariantCulture))
{
case 1:
this._canCreateAccount = base.CurrentUser.GetPrivilege(Privileges.CreateAccount);
break;

case 2:
this._canCreateContact = base.CurrentUser.GetPrivilege(Privileges.CreateContact);
break;

case 3:
this._canCreateOpportunity = base.CurrentUser.GetPrivilege(Privileges.CreateOpportunity);
break;

case 4:
this._canCreateLead = base.CurrentUser.GetPrivilege(Privileges.CreateLead);
break;

case 0x10cc:
this._canCreateList = base.CurrentUser.GetPrivilege(Privileges.CreateList);
break;
}
}
this._showNewButton = ((this._canCreateAccount || this._canCreateContact) || (this._canCreateLead || this._canCreateOpportunity)) || this._canCreateList;
}

What it does, is looking to the specified list of objecttypecodes and looks if any of these match the id of account, contact, lead, opportunity or (marketing)list. If it does not match one of those, then the new button is hidden.

- You can run the javascript code "createNew();”. This is the same function as that will be executed by the button. Running this javascript will open the quickcreate window which will work.

- You can also modify the file ‘lookupsingle.aspx’. In this file there is the function window.onload() function. Modify this function to add these lines to the end:

//enable new button
btnNew.style.display = 'inline';

This will cause the new button to be visible.

That’s about it. Just add the line above and you’ll be ready to go. The new button will now be available for all entities. I haven’t tested this through so that will need to be done in your situation. Also note that this is unsupported and will not be migrated to a potential upgrade to titan or might be lost after an install of a hotfix.

Hope this helps,

Ronald

2 comments:

frederic demeilliez said...

Hi,

thx for the piece of code .. but I have another question.. When hitting the "new" button on the lookup you get a small window with only the "business required" & "business needed" .. But is there a way to open the normal window for adding data ?? So they don't have to enter everything in a small window .. Cz my form is complex and the windows is way to small..

Thx

Ronald Lemmen said...

Hi Frederic,

This behavior is default crm behavior. It is already unsupported to add this button, but adding another line like "btnNew.onClick = window.open('page.aspx','more settings')" will allow you to have more control over what the new button does. You could then point it to the correct page, but it will require quite some work.

In short, you can do everything by modifying this aspx page, but the more you change, the more unsupported you are.

Ronald