how to hide the Option Set field values using java script in MS CRM

//based on am_salesTeam Field in am_leadsourceglobal field option values will be displayed
function hideOptionsetValues() {
    if (Xrm.Page.getAttribute("am_salesteam") != null && Xrm.Page.getAttribute("am_leadsourceglobal") != null) {
        if (Xrm.Page.getAttribute("am_salesteam").getValue() != null) {
            var Salesteam = Xrm.Page.getAttribute("am_salesteam").getValue();
            var LeadsourcedetailglobalValue = null;
            if (Xrm.Page.getAttribute("am_leadsourceglobal") != null && Xrm.Page.getAttribute("am_leadsourceglobal").getValue() != null) {
                LeadsourcedetailglobalValue = Xrm.Page.getAttribute("am_leadsourceglobal").getValue();
            }
            var LeadsourceglobalOptionSet = Xrm.Page.ui.controls.get("am_leadsourceglobal");
            var LeadsourceglobalOptions = LeadsourceglobalOptionSet.getAttribute().getOptions();
            LeadsourceglobalOptionSet.clearOptions();
            if (Salesteam == 930680004 || Salesteam == 930680006 ) { // am_salesTeam
                if (Xrm.Page.ui.controls.get("am_leadsourceglobal") != null)
                    Xrm.Page.ui.controls.get("am_leadsourceglobal").setVisible(true);
                var options = ["930680000", "930680002", "930680001"];//am_leadsourceglobal
                AddOptions(LeadsourceglobalOptions, options, LeadsourceglobalOptionSet);
                if (LeadsourcedetailglobalValue == 930680000)
                    Xrm.Page.getAttribute("am_leadsourceglobal").setValue(930680000);
            }
        }
    }
}
function AddOptions(Options, Values, LeadsourcedetailglobalOptionSet) {
    for (var option = 0; option < Options.length; option++) {
        for (var value = 0; value < Values.length; value++) {
            if (Options[option].value == Values[value])
                LeadsourcedetailglobalOptionSet.addOption(Options[option]);
        }
    }
}

Comments

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest