Monday, July 19, 2010

CRM 4.0 Enhancing Picklists presentation layer

Picklists are usually used to provide a short range of predefined options that further describe our data. To make them usable it’s suggestible to keep the number of Picklist options to a minimum. Although a Picklist presentation layer is functional data is not always that boring and deserves a better re-presentation.

I personally think that controls should convey more emotions and strengthen bond between what is showing and how it’s shown. Take for example a simple Picklist that has values 1-5 that describe the account rating or a Picklist of shipping methods with well known company names. No doubt presenting the following control to the user makes more sense than just selecting a number.

The concept used in this example can be developed further to support more advanced scenarios. The nice thing about it is that most of the bits that handle the actual show and hide of the Picklist menu can be reused. So if you find yourself needing to create a more complex Picklist you should center most of your effort by overriding the buildPopup function (see code).

The code exposes most of the styling attributes which means you don’t have to tear it apart if you feel like redecorating ;+).

In order to facilitate the construction of options and their respective images the code uses a simple technique that accepts an Image base URL and utilizes the picklist id to identify specific images folder. The image names represent their index i.e. 0.gif, 1.gif, 2.gif and so on. If need to use option’s value instead you must also change the code that constructs the image URL.

| -- ISV
|-- IMGPL (this is the ImageBaseUrl)
|-- selected.gif (A small arrow that points to the selected option)
|-- gi_rating (This is the Picklist id)
|-- 0.gif (Empty option X image – index 0)
|-- 1.gif (first option – index 1)
|-- 2.gif (second option – index 2 and so on..,)

Eventually the image URL is http://servername:port/iSV/IMGPL/gi_rating/1.gif
Feel free to comment.

String.prototype.Format = function( args )
return this.replace( /\{(\d{1})\}/ig , function match(){return args[arguments[1]];});

function ImagePicklist(picklistId)
var ipl = this;

if (!(ipl.Picklist = crmForm.all[picklistId]))
return alert("Picklist is missing");

if (ipl.Picklist.Disabled)

ipl.ImageBaseUrl = "/ISV/IMGPL/";
ipl.HoverStyle = {Color: "#FFFFFF",Background: "#000000"}
ipl.HasEmptyOption = true;
ipl.Height = 213;
ipl.BackgroundColor = "#FFFFFF";
ipl.Scroll = true;

ipl.Picklist.ondblclick = function(){show();}
ipl.Picklist.onmousedown = function(){show();}
ipl.Picklist.onfocusout = function()
ipl.Picklist.Popup.document.body.innerHTML = "";

function show()
ipl.Picklist.Disabled = true;
var left = ipl.Picklist.Position.X;
var top = ipl.Picklist.Position.Y;
var width = ipl.Picklist.offsetWidth;
var height = ipl.Height ,top ,width ,ipl.Height ,document.body);
setTimeout(function(){ipl.Picklist.Disabled = false;},100);
return false;

ipl.MouseOver = function(option)
{ = ipl.HoverStyle.Background; = ipl.HoverStyle.Color;

ipl.MouseOut = function(option)
{ = ipl.BackgroundColor; = "#000000";

ipl.Onclick = function(option)
ipl.Picklist.selectedIndex = option.index

function getPosition(control)
var left = 0;
var top = control.offsetHeight;

do {
left += control.offsetLeft;
top += control.offsetTop;
} while (control = control.offsetParent);

return {X:left,Y:top}

function buildPopup()
ipl.Picklist.Position = getPosition(ipl.Picklist); = ipl.BackgroundColor;

var div = document.createElement("DIV"); = "overflow-y:{0};height:{1}px;".Format([(ipl.Scroll?"scroll":"hidden"),(ipl.Height-13)]);

for (var i=(ipl.HasEmptyOption?0:1);i< ipl.Picklist.options.length;i++)
var option = ipl.Picklist.options[i];

var item = document.createElement("DIV");
item.index = i;
item.onmouseover = "document.ImagePicklist.MouseOver(this);";
item.onmouseout = "document.ImagePicklist.MouseOut(this)";
item.onclick = "document.ImagePicklist.Onclick(this)";
item.title = "Value = {0}".Format([option.value]); = "25px" = "hand";

var selItem = null;
if (option.selected)
selItem = document.createElement("IMG"); = "16px"; = "16px";
selItem.src = "{0}selected.gif".Format([ipl.ImageBaseUrl]);
selItem.align = "middle";
selItem = document.createElement("SPAN");
selItem.innerHTML = " "; = "16px";

item.appendChild(document.createTextNode(" "));

var img = document.createElement("IMG");
img.src = "{0}{1}/{2}.gif".Format([ipl.ImageBaseUrl,,i]);

var optText = null;
if (option.selected)
optText = document.createElement("B");
optText.innerText = " {0}".Format([option.innerText]);
optText = document.createTextNode(" {0}".Format([option.innerText]));

ipl.Picklist.Popup.document.body.innerHTML = div.outerHTML;

{ //Initialize

ipl.Picklist.Popup = window.createPopup();
/* A reference from the window popup to ipl */
ipl.Picklist.Popup.document.ImagePicklist = ipl;

var popUpBodyStyle =;
popUpBodyStyle.border = "1px solid gray";
popUpBodyStyle.padding = 0;
popUpBodyStyle.margin = 5;

function OnCrmPageLoad()

window.ctcPicklist = new ImagePicklist("customertypecode");
ctcPicklist.ImageBaseUrl = "/ISV/IMGPL/";
ctcPicklist.HoverStyle = {Color: "gold",Background: "#FF3454"}
ctcPicklist.HasEmptyOption = false;

window.accPicklist = new ImagePicklist("accountcategorycode");
accPicklist.Height = 85;
accPicklist.Scroll = false;
accPicklist.BackgroundColor = "yellow";

window.graPicklist = new ImagePicklist("gi_rating");
graPicklist.Height = 165;
graPicklist.Scroll = false;
graPicklist.HoverStyle = {Color: "navy",Background: "#FFFFFF"}



Paul said...

How do you implement this?

DO I need to copy this code into the onload event for one of my CRM Forms?

Do I have to tweak the code at all for my picklist name?

Microsoft Dynamics CRM said...

I think it's easy to implement in CRM 2011. As we know the CRM 2011 is the latest version than CRM 4.0.

Also the "ImageBaseUrl" was not properly pick the image some time. Should I give the full path?

Flora Liza Geslani said...

Read all the related Posts:

64 Software Manual Testing Interview Questions

Answers To Common Job Interview Questions

Behavioral Questions In Interviews

Questions to Ask at an Interview

Competency based Interview Questions

Read all the related Posts:

How to avoid missing defect in Software Testing?

Defect Management Process

What is the difference between a Test Strategy and Test Plan?

Beginners Guide to ETL Testing

Step by step guide from Test Case Development to Test Execution

microsoft dynamics crm online training said...

its very easy to implement in crm 2011 version better then new version crm 2013

My Sap Gurus said...

Best CRM Online training with quality study materials. Click here to know more about it.

oracle fusion procurement training said...

Commenting on a weblog is a painting. accurate feedback create members of the family. you’re doing brilliant work. very pleasant I genuinely like your weblog......
oracle fusion procurement online training

oraclefusion said...

Thanks for sharing the useful information and good points were stated in the blog which is very useful and for the further information about the oracle visit our site
Oracle Fusion Financials Training

oracle EBS said...

Nice article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.\
Thanks and regards,
Oracle EBS Online training