Answered by:
CRM 4.0 - Drill Down Drop Down Lists

Question
-
Hi,
I am trying to set up a drill down drop down list so when one drop down option changes then only specific items for the option are displayed in another drop down.
Using the following link i have managed to remove options from the drop down
http://sliong.wordpress.com/2011/03/25/crm-4-0-hide-picklist-items-with-javascript-automatically/
However everytime the trigger drop down option is changed it is removing the first option
Code which I have used
var type = crmForm.all.kf_contract.DataValue;
if (type == 1)
{crmForm.all.kf_product.options.remove(1);
}
every time option 1 is selected from the kf_contract drop down it removes the top option from kf_product,
What i would like to do is
if option 1 is selected from kf_contract then the same 2 options show in kf_product and
if option 2 is selected from kf_contract then the related 2 options show in the kf_product drop down and everything else is hidden... and so on.
Any Ideas?
Thank you
Monday, February 17, 2014 10:43 AM
Answers
-
Hi,
I downloaded the following tool http://www.microsoft.com/downloads/details.aspx?FamilyID=634508DC-1762-40D6-B745-B3BDE05D7012&displaylang=en which has generated the code below which works as far as picklist 2 now only contains options relating to what is selected from picklist 1.
// Used to help search the picklist items Array.prototype.Contains = function(o) { var iLength = this.length; for (var i = 0; i < iLength; i++) { if (o == this[i]) { return true; } } return false; }; // This is the main function that will filter the picklists crmForm.FilterPicklist = function x() { var oPrimaryPicklist = crmForm.all.kf_equipmenttype; var oRealatedPicklist = crmForm.all.kf_item; if (oPrimaryPicklist.DataValue == null) { oRealatedPicklist.DataValue = null; oRealatedPicklist.ForceSubmit = true; oRealatedPicklist.Disabled = true; return; } var oTempArray = new Array(); var iLength = oRealatedPicklist.originalPicklistOptions.length; var aCurrentType = new Array(); switch (oPrimaryPicklist.DataValue) { case "1": aCurrentType = new Array(1,2); break; case "2": aCurrentType = new Array(3,4); break; case "3": aCurrentType = new Array(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30); break; } for (var i = 0; i < iLength; i++) { if (aCurrentType.Contains(oRealatedPicklist.originalPicklistOptions[i].DataValue)) { oTempArray.push(oRealatedPicklist.originalPicklistOptions[i]); } } oRealatedPicklist.Options = oTempArray; if (oTempArray.length > 0) { oRealatedPicklist.Disabled = false; } else { oRealatedPicklist.DataValue = null; oRealatedPicklist.ForceSubmit = true; oRealatedPicklist.Disabled = true; } } var CRM_FORM_TYPE_CREATE = 1; var CRM_FORM_TYPE_UPDATE = 2; switch (crmForm.FormType) { case CRM_FORM_TYPE_CREATE://CREATE_FORM - try these and blow away the vars above case CRM_FORM_TYPE_UPDATE: //UPDATE_FORM var oRealatedPicklist = crmForm.all.kf_item; oRealatedPicklist.originalPicklistOptions = oRealatedPicklist.Options; if (crmForm.all.kf_equipmenttype.DataValue == null) { oRealatedPicklist.Disabled = true; } else { var iPicklistValue = oRealatedPicklist.DataValue; crmForm.FilterPicklist(); oRealatedPicklist.DataValue = iPicklistValue; } break; }
However I am only able to select the first option from picklist 2. So even though there is about 20 displayed I am only able to select the first option from picklist 2.
Any advice on how to have it so once picklist 2 has the filtered list, then you can select any item from that list.
I do not understand code hugely so any help with this will really be appreciated.
Thank you :)
- Marked as answer by Kully88 Tuesday, February 18, 2014 12:42 PM
Monday, February 17, 2014 3:56 PM -
i managed to resolve this issue by adding the folowing code on the onChange command of the primary drop down list = kf_equipmenttype
crmForm.FilterPicklist();
I had previously put this code on the primary drop down as well as the related drop down this is why i was having the problem. By taking it off the related drop down list the filtered drop down functionality is working perfectly. :)
- Marked as answer by Kully88 Tuesday, February 18, 2014 12:42 PM
Tuesday, February 18, 2014 12:42 PM
All replies
-
Hi,
I downloaded the following tool http://www.microsoft.com/downloads/details.aspx?FamilyID=634508DC-1762-40D6-B745-B3BDE05D7012&displaylang=en which has generated the code below which works as far as picklist 2 now only contains options relating to what is selected from picklist 1.
// Used to help search the picklist items Array.prototype.Contains = function(o) { var iLength = this.length; for (var i = 0; i < iLength; i++) { if (o == this[i]) { return true; } } return false; }; // This is the main function that will filter the picklists crmForm.FilterPicklist = function x() { var oPrimaryPicklist = crmForm.all.kf_equipmenttype; var oRealatedPicklist = crmForm.all.kf_item; if (oPrimaryPicklist.DataValue == null) { oRealatedPicklist.DataValue = null; oRealatedPicklist.ForceSubmit = true; oRealatedPicklist.Disabled = true; return; } var oTempArray = new Array(); var iLength = oRealatedPicklist.originalPicklistOptions.length; var aCurrentType = new Array(); switch (oPrimaryPicklist.DataValue) { case "1": aCurrentType = new Array(1,2); break; case "2": aCurrentType = new Array(3,4); break; case "3": aCurrentType = new Array(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30); break; } for (var i = 0; i < iLength; i++) { if (aCurrentType.Contains(oRealatedPicklist.originalPicklistOptions[i].DataValue)) { oTempArray.push(oRealatedPicklist.originalPicklistOptions[i]); } } oRealatedPicklist.Options = oTempArray; if (oTempArray.length > 0) { oRealatedPicklist.Disabled = false; } else { oRealatedPicklist.DataValue = null; oRealatedPicklist.ForceSubmit = true; oRealatedPicklist.Disabled = true; } } var CRM_FORM_TYPE_CREATE = 1; var CRM_FORM_TYPE_UPDATE = 2; switch (crmForm.FormType) { case CRM_FORM_TYPE_CREATE://CREATE_FORM - try these and blow away the vars above case CRM_FORM_TYPE_UPDATE: //UPDATE_FORM var oRealatedPicklist = crmForm.all.kf_item; oRealatedPicklist.originalPicklistOptions = oRealatedPicklist.Options; if (crmForm.all.kf_equipmenttype.DataValue == null) { oRealatedPicklist.Disabled = true; } else { var iPicklistValue = oRealatedPicklist.DataValue; crmForm.FilterPicklist(); oRealatedPicklist.DataValue = iPicklistValue; } break; }
However I am only able to select the first option from picklist 2. So even though there is about 20 displayed I am only able to select the first option from picklist 2.
Any advice on how to have it so once picklist 2 has the filtered list, then you can select any item from that list.
I do not understand code hugely so any help with this will really be appreciated.
Thank you :)
- Marked as answer by Kully88 Tuesday, February 18, 2014 12:42 PM
Monday, February 17, 2014 3:56 PM -
i managed to resolve this issue by adding the folowing code on the onChange command of the primary drop down list = kf_equipmenttype
crmForm.FilterPicklist();
I had previously put this code on the primary drop down as well as the related drop down this is why i was having the problem. By taking it off the related drop down list the filtered drop down functionality is working perfectly. :)
- Marked as answer by Kully88 Tuesday, February 18, 2014 12:42 PM
Tuesday, February 18, 2014 12:42 PM