Home > Uncategorized > Custom Lookups in Microsoft CRM

Custom Lookups in Microsoft CRM

If you’re like me and don’t like having to do your own custom lookups as an ISV button, then here is a better way of doing it.  This customization will allow you to implement lookup functionality and have it look like the CRM lookups.  It just looks a lot cleaner.

Adding the Button

First you will need to determine which field you want to add the button to and get the id of the input.  For this example I’ll use the country text field on the Contact form which is address1_country. Then add the following code to the ‘OnLoad’ of the Contact Form.

var beforehtml = "<TABLE class=’lu’ style=’TABLE-LAYOUT: fixed’ cellSpacing=’0′ cellPadding=’0′ width=’100%’><TR><TD>"
var afterhtml = "</td><td width=’25’ align=’right’><img src=’/_imgs/btn_off_lookup.gif’ id=’customlookup’ style=’cursor:hand;’ onclick=’CustomLookup();’/></td></TR></TABLE>"

document.getElementById("address1_country").parentElement.innerHTML = beforehtml + document.getElementById("address1_country").parentElement.innerHTML + afterhtml;

The form should look like this after you publish your changes and open the form. 

Notice the button next to the Country/Region field. This is just a text box but it has a button like a lookup. 

Opening the Lookup

Once you have the button in place you will need to add the onclick function to the ‘OnLoad’ of the Form. Add the following script to the form.  You can develop the custom lookup to do anything you like, you could even pass parameters to the lookup and do whatever you want.  I usually try to make my custom lookups have the same look and feel as crm.

this.CustomLookup = _CustomLookup;
function _CustomLookup()
{
var returnval = window.showModalDialog("/Custom/countrylookup.aspx","","dialogWidth:600px;dialogHeight:488px;
dialogLeft=0px;dialogTop=0px;help:0;status:0;scroll:0;center:1;resizeable:yes;");
if(returnval != "" && returnval != "undefined" && returnval != null)
{
document.getElementById("address1_country").value = returnval;
}
}

Once the user has selected a value from you lookup, set the returnvalue of the window and then it will be assigned to your returnval variable.  Then make sure it actually has a value, and then populate the text box.

You’re good to go. Hope this helps.

 

This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized
  1. October 15, 2012 at 5:35 am

    A motivating discussion is worth comment. I believe that you ought to
    publish more about this issue, it may not be a taboo subject but usually people do not discuss these subjects.
    To the next! Cheers!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: