Quantcast
Channel: CRM Development Forum
Viewing all articles
Browse latest Browse all 888

Dynamic Option Set

$
0
0

Hi, I found this link and realy want it to work regarding filtering the values in a optionset regarding to the value in Another optionset.

http://codestips.com/crm-2011-javascript-filter-option-set/

When I try to make this work on a OnChange event on the "customertypecode" optionset it works the first time. But not if I change tha value again...?

Please help!

I have tried to write to code as follows:

function dynamiskOption(){
   if (Xrm.Page.data.entity.attributes.get("customertypecode").getSelectedOption() == null) {
		   	FilterOptionSet("new_relationshipcategory", [100000012, 100000000, 100000001, 100000005, 100000011, 100000002, 100000004, 100000003, 100000009, 100000007, 100000006, 100000008, 100000013, 100000010, 100000014]);
	}
	else{
		var option = Xrm.Page.getAttribute("customertypecode").getSelectedOption().text;
		if (option == "Logistic") {
			FilterOptionSet("new_relationshipcategory", [100000009, 100000007, 100000006, 100000008]);
		}
		else if (option == "Supplier") {
			FilterOptionSet("new_relationshipcategory", [100000013, 100000010, 100000014]);
		}
		else{
		   	FilterOptionSet("new_relationshipcategory", [100000012, 100000000, 100000001, 100000005, 100000011, 100000002, 100000004, 100000003]);
		}
	}
}
function FilterOptionSet(fieldName, values) {
    var field = Xrm.Page.data.entity.attributes.get(fieldName);
    if (field != null) {
        var options = field.getOptions();
        var control = Xrm.Page.getControl(fieldName);
        //filter option set
        for (var i in options) {
             //The option may be null when no Default Value is set to "Unassigned Value"
            // Skip null value
            if (options[i].value != "null") {
                var valueExist = false;
                for (var j in values) {
                    if (options[i].value == values[j]) {
                        valueExist = true;
                        break;
                    }
                }
                if (!valueExist) {
                    control.removeOption(options[i].value);
                }
            }
        }
    }
}


Viewing all articles
Browse latest Browse all 888

Trending Articles