Thursday 25 February 2016

CASCADE THE TWO OPTION SET FILEDS

Hi

I came across the scenario:

There is a "Discipline" Optionset , "Specialty" Optionset  and "Sub-Specialty" Two Option Set based on the discipline selected the specialty optionset  will filter and based on the filtered options on the specialty the Sub-Specialty selection  will be filtered.

Here is the javascript code to implement the logic...


function disciplineOptionSet_OnChanged() {
    try {

        var optionsetControl = Xrm.Page.ui.controls.get("new_speciality");
        var options = optionsetControl.getAttribute().getOptions();
        var type = Xrm.Page.getAttribute("new_discipline").getValue();
        if (type == 356110000) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110019 || options[i].value == 356110020 || options[i].value == 356110021 || options[i].value == 356110022 || options[i].value == 356110023 || options[i].value == 356110024 || options[i].value == 356110025 || options[i].value == 356110026 || options[i].value == 356110027 || options[i].value == 356110028 || options[i].value == 356110029 || options[i].value == 356110030 || options[i].value == 356110031 || options[i].value == 356110032 || options[i].value == 356110033 || options[i].value == 356110034 || options[i].value == 356110035 || options[i].value == 356110036 || options[i].value == 356110037 || options[i].value == 356110038 || options[i].value == 356110039 || options[i].value == 356110040 || options[i].value == 356110041 || options[i].value == 356110042 || options[i].value == 356110043 || options[i].value == 356110044 || options[i].value == 356110045 || options[i].value == 356110046 || options[i].value == 356110047) {
                    optionsetControl.addOption(options[i], options[i].value);
                }
            }
            //TO DO : Disable/Enable field
        }
        else if (type == 356110001) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110003 || options[i].value == 356110034) {
                    optionsetControl.addOption(options[i], options[i].value);
                }

            }
            //TO DO : Disable/Enable field
        }
        else if (type == 356110002) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110049) {

                    optionsetControl.addOption(options[i], options[i].value);
                }

            }
        }
        else if (type == 356110003) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110050) {
                    optionsetControl.addOption(options[i], options[i].value);
                }

            }
            //TO DO : Disable/Enable field
        }
        else if (type == 356110004) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110051 || options[i].value == 356110052) {

                    optionsetControl.addOption(options[i], options[i].value);
                }

            }
            //TO DO : Disable/Enable field
        }
        else if (type == 356110005) {
            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {
                if (options[i].value == 356110018 || options[i].value == 356110019 || options[i].value == 356110016 || options[i].value == 356110003 || options[i].value == 356110000 || options[i].value == 356110014 || options[i].value == 356110004 || options[i].value == 356110009 || options[i].value == 356110017 || options[i].value == 356110015 || options[i].value == 356110002 || options[i].value == 356110001) {

                    optionsetControl.addOption(options[i], options[i].value);
                }

            }
            //TO DO : Disable/Enable field
        }
        else {

            optionsetControl.clearOptions();
            for (var i = 0; i < options.length - 1; i++) {

                optionsetControl.addOption(options[i]);


            }
            //TO DO : Disable/Enable field
        }
    } catch (e) {
        alert(e);
    }
}
//onLoad event
function Onload_Consultant_Schema() {
    disciplineOptionSet_OnChanged();
    enableDisablesubspecility_OnChange();
}
function onChange_speciality() {
    enableDisablesubspecility_OnChange();
}
enableDisablesubspecility_OnChange = function () {
    //TO DO : Disable all field
    Disable_all_specility_Consultant();
    var type = Xrm.Page.getAttribute("new_speciality").getValue();
    if (type == 356110019) {
        Xrm.Page.getControl("new_anaesthetics").setDisabled(false);
        Xrm.Page.getAttribute("new_anaesthetics").setValue(1);
    } else if (type == 356110020) {
        Xrm.Page.getControl("new_audiologicalmedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_audiologicalmedicine").setValue(1);
    }
    else if (type == 356110021) {
        Xrm.Page.getControl("new_cardiology").setDisabled(false);
        Xrm.Page.getAttribute("new_cardiology").setValue(1);
    }
    else if (type == 356110022) {
        Xrm.Page.getControl("new_clinicalgenetics").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicalgenetics").setValue(1);
    }
    else if (type == 356110023) {
        Xrm.Page.getControl("new_clinicalimmunologyandallergyservice").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicalimmunologyandallergyservice").setValue(1);
    }
    else if (type == 356110024) {
        Xrm.Page.getControl("new_clinicalpharmacology").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicalpharmacology").setValue(1);
    }
    else if (type == 356110025) {
        Xrm.Page.getControl("new_criticalcaremedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_criticalcaremedicine").setValue(1);
    }
    else if (type == 356110026) {
        Xrm.Page.getControl("new_dermatology").setDisabled(false);
        Xrm.Page.getAttribute("new_dermatology").setValue(1);
    }
    else if (type == 356110027) {
        Xrm.Page.getControl("new_endocrinology").setDisabled(false);
        Xrm.Page.getAttribute("new_endocrinology").setValue(1);
    }
    else if (type == 356110028) {
        Xrm.Page.getControl("new_gastroenterology").setDisabled(false);
        Xrm.Page.getAttribute("new_gastroenterology").setValue(1);
    }
    else if (type == 356110004) {
        Xrm.Page.getControl("new_ophthalmology").setDisabled(false);
        Xrm.Page.getAttribute("new_ophthalmology").setValue(1);
    }
    else if (type == 356110009) {
        Xrm.Page.getControl("new_maxillofacialsurgery").setDisabled(false);
        Xrm.Page.getAttribute("new_maxillofacialsurgery").setValue(1);
    }
    else if (type == 356110017) {
        Xrm.Page.getControl("new_paediatricsurgery").setDisabled(false);
        Xrm.Page.getAttribute("new_paediatricsurgery").setValue(1);
    }
    else if (type == 356110015) {
        Xrm.Page.getControl("new_plasticsurgery").setDisabled(false);
        Xrm.Page.getAttribute("new_plasticsurgery").setValue(1);

    }
    else if (type == 356110002) {
        Xrm.Page.getControl("new_traumaorthopaedics").setDisabled(false);
        Xrm.Page.getAttribute("new_traumaorthopaedics").setValue(1);

    }
    else if (type == 356110001) {
        Xrm.Page.getControl("new_urology").setDisabled(false);
        Xrm.Page.getAttribute("new_urology").setValue(1);

    }
    else if (type == 356110000) {
        Xrm.Page.getControl("new_breastsurgery").setDisabled(false);
        Xrm.Page.getControl("new_colorectalsurgery").setDisabled(false);
        Xrm.Page.getControl("new_generalsurgery").setDisabled(false);
        Xrm.Page.getControl("new_transplantationsurgery").setDisabled(false);
        Xrm.Page.getControl("new_uppergastrointestinalsurgery").setDisabled(false);
        Xrm.Page.getControl("new_vascularsurgery").setDisabled(false);
        Xrm.Page.getAttribute("new_breastsurgery").setValue(1);
        Xrm.Page.getAttribute("new_colorectalsurgery").setValue(1);
        Xrm.Page.getAttribute("new_generalsurgery").setValue(1);
        Xrm.Page.getAttribute("new_transplantationsurgery").setValue(1);
        Xrm.Page.getAttribute("new_uppergastrointestinalsurgery").setValue(1);
        Xrm.Page.getAttribute("new_vascularsurgery").setValue(1);

    }
    else if (type == 356110014) {
        Xrm.Page.getControl("new_neurosurgery").setDisabled(false);
        Xrm.Page.getControl("new_spinalsurgeryservice").setDisabled(false);
        Xrm.Page.getAttribute("new_neurosurgery").setValue(1);
        Xrm.Page.getAttribute("new_spinalsurgeryservice").setValue(1);

    }
    else if (type == 356110029) {
        Xrm.Page.getControl("new_clinicalneurophysiology").setDisabled(false);
        Xrm.Page.getControl("new_generalmedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicalneurophysiology").setValue(1);
        Xrm.Page.getAttribute("new_generalmedicine").setValue(1);
    }
    else if (type == 356110030) {
        Xrm.Page.getControl("new_genitourinarymedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_genitourinarymedicine").setValue(1);
    }
    else if (type == 356110031) {
        Xrm.Page.getControl("new_geriatricmedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_geriatricmedicine").setValue(1);
    }
    else if (type == 356110032) {
        Xrm.Page.getControl("new_clinicalhaematology").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicalhaematology").setValue(1);
    }
    else if (type == 356110033) {
        Xrm.Page.getControl("new_infectiousdiseases").setDisabled(false);
        Xrm.Page.getAttribute("new_infectiousdiseases").setValue(1);
    }
    else if (type == 356110034) {
        Xrm.Page.getControl("new_medicaloncology").setDisabled(false);
        Xrm.Page.getAttribute("new_medicaloncology").setValue(1);
    }
    else if (type == 356110035) {
        Xrm.Page.getControl("new_medicalophthalmology").setDisabled(false);
        Xrm.Page.getAttribute("new_medicalophthalmology").setValue(1);
    }
    else if (type == 356110036) {
        Xrm.Page.getControl("new_nephrology").setDisabled(false);
        Xrm.Page.getAttribute("new_nephrology").setValue(1);
    }
    else if (type == 356110037) {
        Xrm.Page.getControl("new_neurology").setDisabled(false);
        Xrm.Page.getAttribute("new_neurology").setValue(1);
    }
    else if (type == 356110038) {
        Xrm.Page.getControl("new_nuclearmedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_nuclearmedicine").setValue(1);
    }
    else if (type == 356110040) {
        Xrm.Page.getControl("new_paediatriccardiology").setDisabled(false);
        Xrm.Page.getAttribute("new_paediatriccardiology").setValue(1);
    }
    else if (type == 356110041) {
        Xrm.Page.getControl("new_paediatricneurology").setDisabled(false);
        Xrm.Page.getAttribute("new_paediatricneurology").setValue(1);
    }
    else if (type == 356110042) {
        Xrm.Page.getControl("new_paediatrics").setDisabled(false);
        Xrm.Page.getAttribute("new_paediatrics").setValue(1);

    } else if (type == 356110043) {
        Xrm.Page.getControl("new_palliativemedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_palliativemedicine").setValue(1);

    }
    else if (type == 356110044) {
        Xrm.Page.getControl("new_rehabilitationservice").setDisabled(false);
        Xrm.Page.getAttribute("new_rehabilitationservice").setValue(1);

    }
    else if (type == 356110045) {
        Xrm.Page.getControl("new_respiratorymedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_respiratorymedicine").setValue(1);

    }
    else if (type == 356110046) {
        Xrm.Page.getControl("new_rheumatology").setDisabled(false);
        Xrm.Page.getAttribute("new_rheumatology").setValue(1);

    }
    else if (type == 356110047) {
        Xrm.Page.getControl("new_sportandexercisemedicine").setDisabled(false);
        Xrm.Page.getAttribute("new_sportandexercisemedicine").setValue(1);

    }
    else if (type == 356110003) {
        Xrm.Page.getControl("new_paediatricearnoseandthroat").setDisabled(false);
        Xrm.Page.getAttribute("new_paediatricearnoseandthroat").setValue(1);

    }
    else if (type == 356110034) {
        Xrm.Page.getControl("new_medicaloncology").setDisabled(false);
        Xrm.Page.getAttribute("new_medicaloncology").setValue(1);

    }
    else if (type == 356110049) {
        Xrm.Page.getControl("new_chemicalpathology").setDisabled(false);
        Xrm.Page.getAttribute("new_chemicalpathology").setValue(1);

    }
    else if (type == 356110050) {
        Xrm.Page.getControl("new_adultmentalillness").setDisabled(false);
        Xrm.Page.getAttribute("new_adultmentalillness").setValue(1);

    }
    else if (type == 356110051) {
        Xrm.Page.getControl("new_clinicaloncology").setDisabled(false);
        Xrm.Page.getAttribute("new_clinicaloncology").setValue(1);

    }//
    else if (type == 356110052) {
        Xrm.Page.getControl("new_diagnosticimaging").setDisabled(false);
        Xrm.Page.getControl("new_interventionalradiology").setDisabled(false);
        Xrm.Page.getAttribute("new_diagnosticimaging").setValue(1);
        Xrm.Page.getAttribute("new_interventionalradiology").setValue(1);

    }
    else if (type == 356110018) {
        Xrm.Page.getControl("new_accidentemergency").setDisabled(false);
        Xrm.Page.getAttribute("new_accidentemergency").setValue(1);

    }
    else if (type == 356110019) {
        Xrm.Page.getControl("new_painmanagement").setDisabled(false);
        Xrm.Page.getAttribute("new_painmanagement").setValue(1);

    }
    else if (type == 356110016) {
        Xrm.Page.getControl("new_cardiacsurgery").setDisabled(false);
        Xrm.Page.getControl("new_cardiothoracicsurgery").setDisabled(false);
        Xrm.Page.getAttribute("new_cardiacsurgery").setValue(1);
        Xrm.Page.getAttribute("new_cardiothoracicsurgery").setValue(1);
    }
    else if (type == 356110003) {
        Xrm.Page.getControl("new_ent").setDisabled(false);
        Xrm.Page.getAttribute("new_ent").setValue(1);

    }
    else if (type == 356110039) {
        Xrm.Page.getControl("new_gynaecologicaloncology").setDisabled(false);
        Xrm.Page.getControl("new_gynaecology").setDisabled(false);
        Xrm.Page.getControl("new_obstetrics").setDisabled(false);
        Xrm.Page.getAttribute("new_gynaecologicaloncology").setValue(1);
        Xrm.Page.getAttribute("new_gynaecology").setValue(1);
        Xrm.Page.getAttribute("new_obstetrics").setValue(1);
    } else {
        Enable_all_specility_Consultant();
    }




}

Disable_all_specility_Consultant = function () {

    Xrm.Page.getControl("new_anaesthetics").setDisabled(true);
    Xrm.Page.getControl("new_audiologicalmedicine").setDisabled(true);
    Xrm.Page.getControl("new_cardiology").setDisabled(true);
    Xrm.Page.getControl("new_clinicalgenetics").setDisabled(true);
    Xrm.Page.getControl("new_clinicalimmunologyandallergyservice").setDisabled(true);
    Xrm.Page.getControl("new_clinicalpharmacology").setDisabled(true);
    Xrm.Page.getControl("new_criticalcaremedicine").setDisabled(true);
    Xrm.Page.getControl("new_dermatology").setDisabled(true);
    Xrm.Page.getControl("new_endocrinology").setDisabled(true);
    Xrm.Page.getControl("new_gastroenterology").setDisabled(true);
    Xrm.Page.getControl("new_ophthalmology").setDisabled(true);
    Xrm.Page.getControl("new_maxillofacialsurgery").setDisabled(true);
    Xrm.Page.getControl("new_paediatricsurgery").setDisabled(true);
    Xrm.Page.getControl("new_plasticsurgery").setDisabled(true);
    Xrm.Page.getControl("new_traumaorthopaedics").setDisabled(true);
    Xrm.Page.getControl("new_urology").setDisabled(true);
    Xrm.Page.getControl("new_breastsurgery").setDisabled(true);
    Xrm.Page.getControl("new_colorectalsurgery").setDisabled(true);
    Xrm.Page.getControl("new_generalsurgery").setDisabled(true);
    Xrm.Page.getControl("new_transplantationsurgery").setDisabled(true);
    Xrm.Page.getControl("new_uppergastrointestinalsurgery").setDisabled(true);
    Xrm.Page.getControl("new_vascularsurgery").setDisabled(true);
    Xrm.Page.getControl("new_neurosurgery").setDisabled(true);
    Xrm.Page.getControl("new_spinalsurgeryservice").setDisabled(true);
    Xrm.Page.getControl("new_clinicalneurophysiology").setDisabled(true);
    Xrm.Page.getControl("new_generalmedicine").setDisabled(true);
    Xrm.Page.getControl("new_genitourinarymedicine").setDisabled(true);
    Xrm.Page.getControl("new_geriatricmedicine").setDisabled(true);
    Xrm.Page.getControl("new_clinicalhaematology").setDisabled(true);
    Xrm.Page.getControl("new_infectiousdiseases").setDisabled(true);
    Xrm.Page.getControl("new_medicaloncology").setDisabled(true);
    Xrm.Page.getControl("new_medicalophthalmology").setDisabled(true);
    Xrm.Page.getControl("new_nephrology").setDisabled(true);
    Xrm.Page.getControl("new_neurology").setDisabled(true);
    Xrm.Page.getControl("new_nuclearmedicine").setDisabled(true);
    Xrm.Page.getControl("new_paediatriccardiology").setDisabled(true);
    Xrm.Page.getControl("new_paediatricneurology").setDisabled(true);
    Xrm.Page.getControl("new_paediatrics").setDisabled(true);
    Xrm.Page.getControl("new_palliativemedicine").setDisabled(true);
    Xrm.Page.getControl("new_rehabilitationservice").setDisabled(true);
    Xrm.Page.getControl("new_respiratorymedicine").setDisabled(true);
    Xrm.Page.getControl("new_rheumatology").setDisabled(true);
    Xrm.Page.getControl("new_sportandexercisemedicine").setDisabled(true);
    Xrm.Page.getControl("new_paediatricearnoseandthroat").setDisabled(true);
    Xrm.Page.getControl("new_medicaloncology").setDisabled(true);
    Xrm.Page.getControl("new_chemicalpathology").setDisabled(true);
    Xrm.Page.getControl("new_adultmentalillness").setDisabled(true);
    Xrm.Page.getControl("new_clinicaloncology").setDisabled(true);
    Xrm.Page.getControl("new_diagnosticimaging").setDisabled(true);
    Xrm.Page.getControl("new_interventionalradiology").setDisabled(true);
    Xrm.Page.getControl("new_accidentemergency").setDisabled(true);
    Xrm.Page.getControl("new_painmanagement").setDisabled(true);
    Xrm.Page.getControl("new_cardiacsurgery").setDisabled(true);
    Xrm.Page.getControl("new_cardiothoracicsurgery").setDisabled(true);
    Xrm.Page.getControl("new_ent").setDisabled(true);
    Xrm.Page.getControl("new_gynaecologicaloncology").setDisabled(true);
    Xrm.Page.getControl("new_gynaecology").setDisabled(true);
    Xrm.Page.getControl("new_obstetrics").setDisabled(true);
    //Given below are the extra field
    Xrm.Page.getControl("new_burnscare").setDisabled(true);
    Xrm.Page.getControl("new_cardiothoracictransplantation").setDisabled(true);
    Xrm.Page.getControl("new_hepatobiliarypancreaticsurgery").setDisabled(true);
    Xrm.Page.getControl("new_oralsurgery").setDisabled(true);
    Xrm.Page.getControl("new_orthodontics").setDisabled(true);
    Xrm.Page.getControl("new_paediatricdentistry").setDisabled(true);
    Xrm.Page.getControl("new_restorativedentistry").setDisabled(true);
    Xrm.Page.getControl("new_spinalsurgeryservice").setDisabled(true);
    Xrm.Page.getControl("new_thoracicsurgery").setDisabled(true);
    Xrm.Page.getControl("new_paediatricmedicaloncology").setDisabled(true);
    //End extra field
    //Set all value to No
    Xrm.Page.getAttribute("new_anaesthetics").setValue(0);
    Xrm.Page.getAttribute("new_audiologicalmedicine").setValue(0);
    Xrm.Page.getAttribute("new_cardiology").setValue(0);
    Xrm.Page.getAttribute("new_clinicalgenetics").setValue(0);
    Xrm.Page.getAttribute("new_clinicalimmunologyandallergyservice").setValue(0);
    Xrm.Page.getAttribute("new_clinicalpharmacology").setValue(0);
    Xrm.Page.getAttribute("new_criticalcaremedicine").setValue(0);
    Xrm.Page.getAttribute("new_dermatology").setValue(0);
    Xrm.Page.getAttribute("new_endocrinology").setValue(0);
    Xrm.Page.getAttribute("new_gastroenterology").setValue(0);
    Xrm.Page.getAttribute("new_ophthalmology").setValue(0);
    Xrm.Page.getAttribute("new_maxillofacialsurgery").setValue(0);
    Xrm.Page.getAttribute("new_paediatricsurgery").setValue(0);
    Xrm.Page.getAttribute("new_plasticsurgery").setValue(0);
    Xrm.Page.getAttribute("new_traumaorthopaedics").setValue(0);
    Xrm.Page.getAttribute("new_urology").setValue(0);
    Xrm.Page.getAttribute("new_breastsurgery").setValue(0);
    Xrm.Page.getAttribute("new_colorectalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_generalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_transplantationsurgery").setValue(0);
    Xrm.Page.getAttribute("new_uppergastrointestinalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_vascularsurgery").setValue(0);
    Xrm.Page.getAttribute("new_neurosurgery").setValue(0);
    Xrm.Page.getAttribute("new_spinalsurgeryservice").setValue(0);
    Xrm.Page.getAttribute("new_clinicalneurophysiology").setValue(0);
    Xrm.Page.getAttribute("new_generalmedicine").setValue(0);
    Xrm.Page.getAttribute("new_genitourinarymedicine").setValue(0);
    Xrm.Page.getAttribute("new_geriatricmedicine").setValue(0);
    Xrm.Page.getAttribute("new_clinicalhaematology").setValue(0);
    Xrm.Page.getAttribute("new_infectiousdiseases").setValue(0);
    Xrm.Page.getAttribute("new_medicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_medicalophthalmology").setValue(0);
    Xrm.Page.getAttribute("new_nephrology").setValue(0);
    Xrm.Page.getAttribute("new_neurology").setValue(0);
    Xrm.Page.getAttribute("new_nuclearmedicine").setValue(0);
    Xrm.Page.getAttribute("new_paediatriccardiology").setValue(0);
    Xrm.Page.getAttribute("new_paediatricneurology").setValue(0);
    Xrm.Page.getAttribute("new_paediatrics").setValue(0);
    Xrm.Page.getAttribute("new_palliativemedicine").setValue(0);
    Xrm.Page.getAttribute("new_rehabilitationservice").setValue(0);
    Xrm.Page.getAttribute("new_respiratorymedicine").setValue(0);
    Xrm.Page.getAttribute("new_rheumatology").setValue(0);
    Xrm.Page.getAttribute("new_sportandexercisemedicine").setValue(0);
    Xrm.Page.getAttribute("new_paediatricearnoseandthroat").setValue(0);
    Xrm.Page.getAttribute("new_medicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_chemicalpathology").setValue(0);
    Xrm.Page.getAttribute("new_adultmentalillness").setValue(0);
    Xrm.Page.getAttribute("new_clinicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_diagnosticimaging").setValue(0);
    Xrm.Page.getAttribute("new_interventionalradiology").setValue(0);
    Xrm.Page.getAttribute("new_accidentemergency").setValue(0);
    Xrm.Page.getAttribute("new_painmanagement").setValue(0);
    Xrm.Page.getAttribute("new_cardiacsurgery").setValue(0);
    Xrm.Page.getAttribute("new_cardiothoracicsurgery").setValue(0);
    Xrm.Page.getAttribute("new_ent").setValue(0);
    Xrm.Page.getAttribute("new_gynaecologicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_gynaecology").setValue(0);
    Xrm.Page.getAttribute("new_obstetrics").setValue(0);
    //Given below are the extra field
    Xrm.Page.getAttribute("new_burnscare").setValue(0);
    Xrm.Page.getAttribute("new_cardiothoracictransplantation").setValue(0);
    Xrm.Page.getAttribute("new_hepatobiliarypancreaticsurgery").setValue(0);
    Xrm.Page.getAttribute("new_oralsurgery").setValue(0);
    Xrm.Page.getAttribute("new_orthodontics").setValue(0);
    Xrm.Page.getAttribute("new_paediatricdentistry").setValue(0);
    Xrm.Page.getAttribute("new_restorativedentistry").setValue(0);
    Xrm.Page.getAttribute("new_spinalsurgeryservice").setValue(0);
    Xrm.Page.getAttribute("new_thoracicsurgery").setValue(0);
    Xrm.Page.getAttribute("new_paediatricmedicaloncology").setValue(0);

}

Enable_all_specility_Consultant = function () {
    Xrm.Page.getControl("new_anaesthetics").setDisabled(false);
    Xrm.Page.getControl("new_audiologicalmedicine").setDisabled(false);
    Xrm.Page.getControl("new_cardiology").setDisabled(false);
    Xrm.Page.getControl("new_clinicalgenetics").setDisabled(false);
    Xrm.Page.getControl("new_clinicalimmunologyandallergyservice").setDisabled(false);
    Xrm.Page.getControl("new_clinicalpharmacology").setDisabled(false);
    Xrm.Page.getControl("new_criticalcaremedicine").setDisabled(false);
    Xrm.Page.getControl("new_dermatology").setDisabled(false);
    Xrm.Page.getControl("new_endocrinology").setDisabled(false);
    Xrm.Page.getControl("new_gastroenterology").setDisabled(false);
    Xrm.Page.getControl("new_ophthalmology").setDisabled(false);
    Xrm.Page.getControl("new_maxillofacialsurgery").setDisabled(false);
    Xrm.Page.getControl("new_paediatricsurgery").setDisabled(false);
    Xrm.Page.getControl("new_plasticsurgery").setDisabled(false);
    Xrm.Page.getControl("new_traumaorthopaedics").setDisabled(false);
    Xrm.Page.getControl("new_urology").setDisabled(false);
    Xrm.Page.getControl("new_breastsurgery").setDisabled(false);
    Xrm.Page.getControl("new_colorectalsurgery").setDisabled(false);
    Xrm.Page.getControl("new_generalsurgery").setDisabled(false);
    Xrm.Page.getControl("new_transplantationsurgery").setDisabled(false);
    Xrm.Page.getControl("new_uppergastrointestinalsurgery").setDisabled(false);
    Xrm.Page.getControl("new_vascularsurgery").setDisabled(false);
    Xrm.Page.getControl("new_neurosurgery").setDisabled(false);
    Xrm.Page.getControl("new_spinalsurgeryservice").setDisabled(false);
    Xrm.Page.getControl("new_clinicalneurophysiology").setDisabled(false);
    Xrm.Page.getControl("new_generalmedicine").setDisabled(false);
    Xrm.Page.getControl("new_genitourinarymedicine").setDisabled(false);
    Xrm.Page.getControl("new_geriatricmedicine").setDisabled(false);
    Xrm.Page.getControl("new_clinicalhaematology").setDisabled(false);
    Xrm.Page.getControl("new_infectiousdiseases").setDisabled(false);
    Xrm.Page.getControl("new_medicaloncology").setDisabled(false);
    Xrm.Page.getControl("new_medicalophthalmology").setDisabled(false);
    Xrm.Page.getControl("new_nephrology").setDisabled(false);
    Xrm.Page.getControl("new_neurology").setDisabled(false);
    Xrm.Page.getControl("new_nuclearmedicine").setDisabled(false);
    Xrm.Page.getControl("new_paediatriccardiology").setDisabled(false);
    Xrm.Page.getControl("new_paediatricneurology").setDisabled(false);
    Xrm.Page.getControl("new_paediatrics").setDisabled(false);
    Xrm.Page.getControl("new_palliativemedicine").setDisabled(false);
    Xrm.Page.getControl("new_rehabilitationservice").setDisabled(false);
    Xrm.Page.getControl("new_respiratorymedicine").setDisabled(false);
    Xrm.Page.getControl("new_rheumatology").setDisabled(false);
    Xrm.Page.getControl("new_sportandexercisemedicine").setDisabled(false);
    Xrm.Page.getControl("new_paediatricearnoseandthroat").setDisabled(false);
    Xrm.Page.getControl("new_medicaloncology").setDisabled(false);
    Xrm.Page.getControl("new_chemicalpathology").setDisabled(false);
    Xrm.Page.getControl("new_adultmentalillness").setDisabled(false);
    Xrm.Page.getControl("new_clinicaloncology").setDisabled(false);
    Xrm.Page.getControl("new_diagnosticimaging").setDisabled(false);
    Xrm.Page.getControl("new_interventionalradiology").setDisabled(false);
    Xrm.Page.getControl("new_accidentemergency").setDisabled(false);
    Xrm.Page.getControl("new_painmanagement").setDisabled(false);
    Xrm.Page.getControl("new_cardiacsurgery").setDisabled(false);
    Xrm.Page.getControl("new_cardiothoracicsurgery").setDisabled(false);
    Xrm.Page.getControl("new_ent").setDisabled(false);
    Xrm.Page.getControl("new_gynaecologicaloncology").setDisabled(false);
    Xrm.Page.getControl("new_gynaecology").setDisabled(false);
    Xrm.Page.getControl("new_obstetrics").setDisabled(false);
    //Given below are the extra field
    Xrm.Page.getControl("new_burnscare").setDisabled(false);
    Xrm.Page.getControl("new_cardiothoracictransplantation").setDisabled(false);
    Xrm.Page.getControl("new_hepatobiliarypancreaticsurgery").setDisabled(false);
    Xrm.Page.getControl("new_oralsurgery").setDisabled(false);
    Xrm.Page.getControl("new_orthodontics").setDisabled(false);
    Xrm.Page.getControl("new_paediatricdentistry").setDisabled(false);
    Xrm.Page.getControl("new_restorativedentistry").setDisabled(false);
    Xrm.Page.getControl("new_spinalsurgeryservice").setDisabled(false);
    Xrm.Page.getControl("new_thoracicsurgery").setDisabled(false);
    Xrm.Page.getControl("new_paediatricmedicaloncology").setDisabled(false);
    //Setting the value 1
    Xrm.Page.getAttribute("new_anaesthetics").setValue(0);
    Xrm.Page.getAttribute("new_audiologicalmedicine").setValue(0);
    Xrm.Page.getAttribute("new_cardiology").setValue(0);
    Xrm.Page.getAttribute("new_clinicalgenetics").setValue(0);
    Xrm.Page.getAttribute("new_clinicalimmunologyandallergyservice").setValue(0);
    Xrm.Page.getAttribute("new_clinicalpharmacology").setValue(0);
    Xrm.Page.getAttribute("new_criticalcaremedicine").setValue(0);
    Xrm.Page.getAttribute("new_dermatology").setValue(0);
    Xrm.Page.getAttribute("new_endocrinology").setValue(0);
    Xrm.Page.getAttribute("new_gastroenterology").setValue(0);
    Xrm.Page.getAttribute("new_ophthalmology").setValue(0);
    Xrm.Page.getAttribute("new_maxillofacialsurgery").setValue(0);
    Xrm.Page.getAttribute("new_paediatricsurgery").setValue(0);
    Xrm.Page.getAttribute("new_plasticsurgery").setValue(0);
    Xrm.Page.getAttribute("new_traumaorthopaedics").setValue(0);
    Xrm.Page.getAttribute("new_urology").setValue(0);
    Xrm.Page.getAttribute("new_breastsurgery").setValue(0);
    Xrm.Page.getAttribute("new_colorectalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_generalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_transplantationsurgery").setValue(0);
    Xrm.Page.getAttribute("new_uppergastrointestinalsurgery").setValue(0);
    Xrm.Page.getAttribute("new_vascularsurgery").setValue(0);
    Xrm.Page.getAttribute("new_neurosurgery").setValue(0);
    Xrm.Page.getAttribute("new_spinalsurgeryservice").setValue(0);
    Xrm.Page.getAttribute("new_clinicalneurophysiology").setValue(0);
    Xrm.Page.getAttribute("new_generalmedicine").setValue(0);
    Xrm.Page.getAttribute("new_genitourinarymedicine").setValue(0);
    Xrm.Page.getAttribute("new_geriatricmedicine").setValue(0);
    Xrm.Page.getAttribute("new_clinicalhaematology").setValue(0);
    Xrm.Page.getAttribute("new_infectiousdiseases").setValue(0);
    Xrm.Page.getAttribute("new_medicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_medicalophthalmology").setValue(0);
    Xrm.Page.getAttribute("new_nephrology").setValue(0);
    Xrm.Page.getAttribute("new_neurology").setValue(0);
    Xrm.Page.getAttribute("new_nuclearmedicine").setValue(0);
    Xrm.Page.getAttribute("new_paediatriccardiology").setValue(0);
    Xrm.Page.getAttribute("new_paediatricneurology").setValue(0);
    Xrm.Page.getAttribute("new_paediatrics").setValue(0);
    Xrm.Page.getAttribute("new_palliativemedicine").setValue(0);
    Xrm.Page.getAttribute("new_rehabilitationservice").setValue(0);
    Xrm.Page.getAttribute("new_respiratorymedicine").setValue(0);
    Xrm.Page.getAttribute("new_rheumatology").setValue(0);
    Xrm.Page.getAttribute("new_sportandexercisemedicine").setValue(0);
    Xrm.Page.getAttribute("new_paediatricearnoseandthroat").setValue(0);
    Xrm.Page.getAttribute("new_medicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_chemicalpathology").setValue(0);
    Xrm.Page.getAttribute("new_adultmentalillness").setValue(0);
    Xrm.Page.getAttribute("new_clinicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_diagnosticimaging").setValue(0);
    Xrm.Page.getAttribute("new_interventionalradiology").setValue(0);
    Xrm.Page.getAttribute("new_accidentemergency").setValue(0);
    Xrm.Page.getAttribute("new_painmanagement").setValue(0);
    Xrm.Page.getAttribute("new_cardiacsurgery").setValue(0);
    Xrm.Page.getAttribute("new_cardiothoracicsurgery").setValue(0);
    Xrm.Page.getAttribute("new_ent").setValue(0);
    Xrm.Page.getAttribute("new_gynaecologicaloncology").setValue(0);
    Xrm.Page.getAttribute("new_gynaecology").setValue(0);
    Xrm.Page.getAttribute("new_obstetrics").setValue(0);
    //Given below are the extra field
    Xrm.Page.getAttribute("new_burnscare").setValue(0);
    Xrm.Page.getAttribute("new_cardiothoracictransplantation").setValue(0);
    Xrm.Page.getAttribute("new_hepatobiliarypancreaticsurgery").setValue(0);
    Xrm.Page.getAttribute("new_oralsurgery").setValue(0);
    Xrm.Page.getAttribute("new_orthodontics").setValue(0);
    Xrm.Page.getAttribute("new_paediatricdentistry").setValue(0);
    Xrm.Page.getAttribute("new_restorativedentistry").setValue(0);
    Xrm.Page.getAttribute("new_spinalsurgeryservice").setValue(0);
    Xrm.Page.getAttribute("new_thoracicsurgery").setValue(0);
    Xrm.Page.getAttribute("new_paediatricmedicaloncology").setValue(0);
}

function OnSave_NameConcatnation() {
    var firstName = Xrm.Page.getAttribute("new_firstname").getValue();
    var lastName = Xrm.Page.getAttribute("new_lastname").getValue();
    Xrm.Page.getAttribute("new_name").setValue(firstName + " " + lastName);
}

function EmailValidation_Primaryemailaddress() {

    var primaryemailaddress = Xrm.Page.getAttribute("new_primaryemailaddress").getValue();
    if (primaryemailaddress != null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(primaryemailaddress)) {
            Xrm.Page.getControl("new_primaryemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_primaryemailaddress").setFocus();


        }
    } else {
        Xrm.Page.getControl("new_primaryemailaddress").clearNotification();

    }

}
function EmailValidation_Secondaryemailaddress() {

    var secondaryemailaddress = Xrm.Page.getAttribute("new_secondaryemailaddress").getValue();
    if (secondaryemailaddress != null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(secondaryemailaddress)) {
            Xrm.Page.getControl("new_secondaryemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_secondaryemailaddress").setFocus();

        }
    } else {
        Xrm.Page.getControl("new_secondaryemailaddress").clearNotification();
    }

}
function EmailValidation_primarymedicalsecretarypaemailaddress() {

    var primarymedicalsecretarypaemailaddress = Xrm.Page.getAttribute("new_primarymedicalsecretarypaemailaddress").getValue();
    if (primarymedicalsecretarypaemailaddress != null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(primarymedicalsecretarypaemailaddress)) {
            Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").setFocus();

        }
    } else {
        Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").clearNotification();
    }

}

EMAIL FIELD VALIDATION MS CRM

Hi 


I had a scenario which everyone aware of the email field validation


function EmailValidation_Primaryemailaddress() {

    var primaryemailaddress = Xrm.Page.getAttribute("new_primaryemailaddress").getValue();
    if (primaryemailaddress != null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(primaryemailaddress)) {
            Xrm.Page.getControl("new_primaryemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_primaryemailaddress").setFocus();


        }
    } else {
        Xrm.Page.getControl("new_primaryemailaddress").clearNotification();

    }

}
function EmailValidation_Secondaryemailaddress() {

    var secondaryemailaddress = Xrm.Page.getAttribute("new_secondaryemailaddress").getValue();
    if (secondaryemailaddress!=null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(secondaryemailaddress)) {
            Xrm.Page.getControl("new_secondaryemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_secondaryemailaddress").setFocus();

        }
    } else {
        Xrm.Page.getControl("new_secondaryemailaddress").clearNotification();
    }
    
}
function EmailValidation_primarymedicalsecretarypaemailaddress() {

    var primarymedicalsecretarypaemailaddress = Xrm.Page.getAttribute("new_primarymedicalsecretarypaemailaddress").getValue();
    if (primarymedicalsecretarypaemailaddress!=null) {
        var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
        if (!reg.test(primarymedicalsecretarypaemailaddress)) {
            Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").setNotification("please enter valid email address");
            Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").setFocus();

        }
    } else {
        Xrm.Page.getControl("new_primarymedicalsecretarypaemailaddress").clearNotification();
    }
   
}

I hope this helps 

Happy CRMing

Saturday 20 February 2016

Custom Workflow Input and Output Parmeters in CRM

Custom Workflow Input and Output Parmeters in CRM

Hi,

Today I got a requirement to create a task and assign it to the Manager of the Owner on the Parent Record. We can easily get the Owner value in the system workflow but not the Manager of the owner.

For this I had to write a custom workflow which will take Owner value as an Input Parameter and returns Manager of the Owner as an Output Parameter.

Here is the way to declare Input and Output Parameter in a Custom Workflow.

/// <summary>
/// Input Argument - SystemUser
/// </summary>
[RequiredArgument]
[Input("User")]
[ReferenceTarget("systemuser")]
public InArgument<EntityReference> User { getset; }

/// <summary>
/// Output Arugument - Manager of the user.
/// </summary>
[Output("Manager of the user")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> Manager { getset; }

And this the below code in the Workflow Execute Method.

// Get the Manager of the user.
EntityReference erfUser = User.Get<EntityReference>(executionContext);
Entity entityUser = service.Retrieve("systemuser", erfUser.Id, new ColumnSet(newstring[] { "parentsystemuserid" }));
Manager.Set(executionContext, (EntityReference)entityUser.Attributes["parentsystemuserid"]);

After this, just build your project and deploy it in CRM and use the same in the system workflow by passing the Owner value and it will give the Manager of the owner. 

In the same way, we can using CRM Custom Workflow for many business operations by using Input and Output Parameters.

I Hope this helps

Happy CRM'ing!

 

Friday 19 February 2016

CASCADING TWO OPTIONSETS IN MS CRM 2015



/*
1. Create one seperate Jscript file.
2. Onload_Consultant_Schema() function attached onLoad event on Consultant 
3. disciplineOptionSet_OnChanged() function attached onChange event on Discipline attribute on consultant


*/

//onChange event
disciplineOptionSet_OnChanged = function () {
    var optionsetControl = Xrm.Page.ui.controls.get("new_subspecility");//this is the child or dependent optionSet
    var options = optionsetControl.getAttribute().getOptions();
    var type = Xrm.Page.getAttribute("new_discipline").getValue();//this is the parent optionSet
    if (type == 356110000) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (   options[i].value == 356110019
                || options[i].value == 356110020
                || options[i].value == 356110021
                || options[i].value == 356110022
                || options[i].value == 356110023
                || options[i].value == 356110024
                || options[i].value == 356110025
                || options[i].value == 356110026
                || options[i].value == 356110027
                || options[i].value == 356110028
                || options[i].value == 356110029
                || options[i].value == 356110030
                || options[i].value == 356110031
                || options[i].value == 356110032
                || options[i].value == 356110033
                || options[i].value == 356110034
                || options[i].value == 356110035
                || options[i].value == 356110036
                || options[i].value == 356110037
                || options[i].value == 356110038
                || options[i].value == 356110039
                || options[i].value == 356110040
                || options[i].value == 356110041
                || options[i].value == 356110042
                || options[i].value == 356110043
                || options[i].value == 356110044
                || options[i].value == 356110045
                || options[i].value == 356110046
                || options[i].value == 356110047
                ) {
                optionsetControl.addOption(options[i]);
            }
        }
        //TO DO : Disable/Enable field
    }
    else if (type == 356110001) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (options[i].value == 356110003 || options[i].value == 356110034) {
                optionsetControl.addOption(options[i]);
            }

        }
        //TO DO : Disable/Enable field
    }
    else if (type == 356110002) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (options[i].value == 356110049) {
                optionsetControl.addOption(options[i]);
            }

        }
    }
    else if (type == 356110003) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (options[i].value == 356110050) {
                optionsetControl.addOption(options[i]);
            }

        }
        //TO DO : Disable/Enable field
    }
    else if (type == 356110004) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (options[i].value == 356110051 || options[i].value == 356110052) {
                optionsetControl.addOption(options[i]);
            }

        }
        //TO DO : Disable/Enable field
    }
    else if (type == 356110005) {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {
            if (   options[i].value == 356110018
                || options[i].value == 356110019
                || options[i].value == 356110016
                || options[i].value == 356110003
                || options[i].value == 356110000
                || options[i].value == 356110014
                || options[i].value == 356110004
                || options[i].value == 356110009
                || options[i].value == 356110017
                || options[i].value == 356110015
                || options[i].value == 356110002
                || options[i].value == 356110001
                ) {
                optionsetControl.addOption(options[i]);
            }

        }
        //TO DO : Disable/Enable field
    }
    else {
        optionsetControl.clearOptions();
        for (var i = 0; i < options.length - 1; i++) {

            optionsetControl.addOption(options[i]);


        }
        //TO DO : Disable/Enable field
    }

}
//onLoad event
Onload_Consultant_Schema = function () {
    disciplineOptionSet_OnChanged();
}

HOW TO INTEGRATE MICROSOFT DYNAMICS CRM 2015 WITH MICROSOFT SHAREPOINT 2013



In this article we will see the procedure to integrate Microsoft Dynamics CRM 2015 with Microsoft SharePoint 2013, both on-premise installations.
You can use the document management capabilities of SharePoint from within Microsoft Dynamics CRM. You can store and manage documents in the context of a Microsoft Dynamics CRM record on a server that is running SharePoint and leverage the SharePoint infrastructure to share, manage and collaborate efficiently. Because the documents are stored on a server that is running SharePoint, non-Microsoft Dynamics CRM users can directly access the documents on the server, provided they have the appropriate permissions on the server that is running SharePoint Server to do so. 
Step 1: Click on CRM -> Settings -> Document Management as shown below.
 
 
Step 2: You will settings available under the document management settings.
 
 
Step 3: Click on Document Management Settings, enter the SharePoint site URL where you want to save documents. Click Next. In case you don't have the Microsoft Dynamics CRM List Component it will give you the following warning.
 
 
 
Step 4: We need to setup SharePoint for this List Component. For that download the List component for the correct version of CRM and upload it into the Solutions Gallery of SharePoint.
 
 
 
Step 5:  Activate the solution and be sure that the Status is activated.
 
 
 
You may get errors in activation. To rectify, make sure the Microsoft Dynamics CRM Sandbox Processing Service and Microsoft SharePoint foundation Sandboxed Code Service services are started.  
 
 
 
Step 6:  Document management can be enabled for those entities in Microsoft Dynamics CRM that can be customized. By default, document management is enabled only for the following entities in a new installation of CRM.
  •  Account 
  •  KbArticle 
  •  Lead 
  •  Opportunity 
  •  Product 
  •  Quote 
  •  SalesLiterature
You can enable document management for an entity, as shown below.
 
 
 
Step 7: Once document management is enabled for an entity, you will see the option for documents as shown below.
 
 
 
Step 8:  You can add document location for this entity assuming the location is created and the appropriate permissions are set on SharePoint.
 
 
 
Step 9: And if everything goes right, you will see the familiar (at least to me) interface of SharePoint from within Dynamics CRM as shown below. You can start uploading documents and use document management functionality.
 
 
 
Step 10: In case you do not want to manage the folder structure on your own and let CRM make it for you, if the CRM List Component is installed correctly, you get an option for creating a folder structure based on the entities.
 
 
 
CRM users and non-CRM users can work together to achieve common business goals through improved communication by this integration.