function form_OnLoad() {
    Xrm.Page.getControl("vhacrm_correspondencetemplateid").addPreSearch(function () {
        addLookupFilter();
    });

    // Exclude Email from Correspondence Type optionset
    setupTypeOptionSet();
 
}
function addLookupFilter() {
    var ctype = Xrm.Page.getAttribute("vhacrm_correspondencetype_code").getValue();
    if (ctype != null) {
        fetchXml = "<filter type='and'><condition attribute='vhacrm_correspondencetype_code' operator='eq' value='" + ctype + "' /></filter>"; Xrm.Page.getControl("vhacrm_correspondencetemplateid").addCustomFilter(fetchXml);
    }
}

function setupTypeOptionSet() {
    var optEmailValue = 713770001;
    var pickList = Xrm.Page.getControl("vhacrm_correspondencetype_code");

    if (pickList != null) {
        // Remove Email option from optionset
        pickList.removeOption(optEmailValue);
    }
}