function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jaicen83Jaicen83 

getDependentPicklistOptions No Longer Working in Winter 16 Maybe because of Java Changes

Here is the Static Resourcer
/**
 * getDependentPicklistOptions
 *
 * Build an Object in which keys are valid options for the controlling field
 * and values are lists of valid options for the dependent field.
 *
 * Method: dependent PickListEntry.validFor provides a base64 encoded
 * string. After decoding, each of the bits (reading L to R)
 * corresponds to the picklist values for the controlling field.
 */
function getDependentOptions (objName, ctrlFieldName, depFieldName) {
	// Isolate the Describe info for the relevant fields
	var objDesc = sforce.connection.describeSObject(objName);
	var ctrlFieldDesc, depFieldDesc;
	var found = 0;
	for (var i=0; i<objDesc.fields.length; i++) {
		var f = objDesc.fields[i];
		if (f.name == ctrlFieldName) {
			ctrlFieldDesc = f;
			found++;
		} else if (f.name == depFieldName) {
			depFieldDesc = f;
			found++;
		}
		if (found==2) break; 
	}

	// Set up return object
	var dependentOptions = {};
	var ctrlValues = ctrlFieldDesc.picklistValues;
	for (var i=0; i<ctrlValues.length; i++) {
		dependentOptions[ctrlValues[i].label] = [];
	}

	var base64 = new sforce.Base64Binary("");
	function testBit (validFor, pos) {
		var byteToCheck = Math.floor(pos/8);
		var bit = 7 - (pos % 8);
		return ((Math.pow(2, bit) & validFor.charCodeAt(byteToCheck)) >> bit) == 1;
	}
	
	// For each dependent value, check whether it is valid for each controlling value
	var depValues = depFieldDesc.picklistValues;
	for (var i=0; i<depValues.length; i++) {
		var thisOption = depValues[i];
		var validForDec = base64.decode(thisOption.validFor);
		for (var ctrlValue=0; ctrlValue<ctrlValues.length; ctrlValue++) {
			if (testBit(validForDec, ctrlValue)) {
				dependentOptions[ctrlValues[ctrlValue].label].push(thisOption.label);
			}
		}
	}
	return dependentOptions;
}

/*
var OBJ_NAME = 'Custom_Object__c';
var CTRL_FIELD_NAME = "Controlling_Field__c";
var DEP_FIELD_NAME = "Dependent_Field__c";
var options = getDependentOptions(OBJ_NAME, CTRL_FIELD_NAME, DEP_FIELD_NAME);
console.debug(options);
*/

Here is the script on the Visualforce page which overrides the standard add products button on the quote line item
 
<script>
        var j$  = jQuery.noConflict();
        j$(document).ready(function()  {
            var OBJ_NAME = 'Product2';
            var CTRL_FIELD_NAME = 'Family';
            var DEP_FIELD_NAME = 'Product_Group__c';
            
            if ('{!prod.Family}' != '') {
                var options = getDependentOptions(OBJ_NAME, CTRL_FIELD_NAME, DEP_FIELD_NAME);
                options['{!prod.Family}'].sort();
                
                j$.each(options['{!prod.Family}'], function (i, item) {
                    j$('.selectProductGroup').append('<option value="'+item+'">'+item+'</option>');
                });
                
                j$('.selectProductGroup').change(function() {
                    j$('.selectProductGroupHidden').val(j$('.selectProductGroup').val());
                });
                
                $(".selectProductGroup option[value='']").attr("selected", "selected");
                j$('.selectProductGroup').val(j$('.selectProductGroupHidden').val());
                
            }
        });
    
    </script>

All this Code has been working properly for 2 years and when Winter 16 launched it doesn't.

User-added image

Product group is a dependant picklist off of Product Family which is labeled as Product Line. After the cutover product group in no longer displaing the list of values
 
Andy BoettcherAndy Boettcher
Do you get any Javascript console errors when loading or running this page?  With everything being Javascript you should get SOME kind of error if something has changed from the JS point of view.
Jaicen83Jaicen83
There is no Java sript errors and everything else on the page runs fine.

Here is the initiation code on the VisualForce Page.
<apex:page tabstyle="Quote" showHeader="true" standardController="Quote" extensions="ManageQuoteProductController" id="ManageQuoteProduct">

<script src="sorttable.js"></script>

    <apex:includeScript value="{!$Resource.DependentPicklist}" />
    <apex:includeScript value="{!$Resource.jquery180}" />
  
    <apex:pageBlock id="ProductLineBlock" title="Manage Product">
    <apex:form >
     <p align="center">
        <apex:commandButton value="Close" action="{!cancelManageProduct}" />
     </p>
     </apex:form>
     <apex:pageblockSection ></apex:pageblockSection>
     <apex:pageMessages id="msgs" />