function form_OnLoad() {
    Xrm.Page.getControl("DNS_correspondencetemplateid").addPreSearch(function () {
        addLookupFilter();
    });
}
function addLookupFilter() {
    var ctype = Xrm.Page.getAttribute("DNS_correspondencetype_code").getValue();
    if (ctype != null) {
        fetchXml = "<filter type='and'><condition attribute='DNS_correspondencetype_code' operator='eq' value='" + ctype + "' /></filter>"; Xrm.Page.getControl("DNS_correspondencetemplateid").addCustomFilter(fetchXml);
    }
}