| Guy Riddle's profileMicrosoft Dynamics CRMBlogLists | Help |
|
May 10 Dynamic filtering of picklist valuesThis is a great technique, especially if you want to base the values of one picklist field based on what a user selected in a previous picklist field.
I have even used a similar technique for controlling data entry for Country, State and Suburb - by simply adding three 'dummy' picklist fields that contain the appropriate values, then using this picklist filtering method; and finally using a small piece of Jscript code to move the value of the dummy picklist field to the 'real' CRM field.
Note - don't replace these address fields completely with picklist fields, The address fields come up in many places and you will find that you can create issues down the track.
// Set the Country
var oCountry = crmForm.all.mycountryfield;
// Initialize the State indexes
var iStartIndex = -1;
var iEndIndex = -1;
// Depending on what Country the user selects we will select
// a range of options in the State picklist to display.
//
// In this example, it is assumed that the display text of each
// Country will be known; also, all the State values
// in the State picklist are group sequentially per
// Country. This makes coding easier.
switch (oCountry.SelectedText) {
case "Australia":
iStartIndex = 1;
iEndIndex = 8;
break;
case "USA":
iStartIndex = 9;
iEndIndex = 59;
// Note - the start/end indexes must relate to the order of the values in the picklist
break;
}
// Set the State
var oState = crmForm.all.mystatefield;
if (iStartIndex > -1 && iEndIndex > -1)
{
// Create an array to hold the picklist values
var oTempArray = new Array();
// Initialise the array index
var iIndex = 0;
// Read the State options and move only the
// requested options into the array.
for (var i = iStartIndex; i <= iEndIndex; i++)
{
oTempArray[iIndex] = oState.originalPicklistOptions[i];
iIndex++;
}
// Reset the State picklist with the new options
oState.Options = oTempArray;
// Enable the State picklist for the user
oState.Disabled = false;
}
else
{
// If there is no State
oState.DataValue = null;
oState.Disabled = true;
}
Comments (7)
Trackbacks (0)The trackback URL for this entry is: http://guyriddle.spaces.live.com/blog/cns!5D4E0DC4D1513384!126.trak Weblogs that reference this entry
|
|
|