hi all
i created filter lookup using javascript in crm 2013 but am getting errors
/ FUNCTION: FilterCDA
function FilterCDA(patientFieldName, lookupFieldName) {
var isPatient = window.parent.opener.Xrm.Page.getAttribute("ccx_expectedaudience").getValue();
if (isPatient == 803080000) {
setLookup(patientFieldName, lookupFieldName);
}
}
// FUNCTION: setLookup
function setLookup(patientFieldName, lookupFieldName) {
// Get the selected Account Id in the [patientFieldName] indicated control
// var patientId = window.parent.opener.Xrm.Page.getAttribute(patientFieldName).getValue()[0].id;
var patient = window.parent.opener.Xrm.Page.getAttribute(patientFieldName).getValue();
if (patient != null) {
var patientId = patient[0].id;
var patientName = patient[0].name;
// use randomly generated GUID Id for our new view
defaultViewId = Xrm.Page.getControl(lookupFieldName).getDefaultView();
// var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}";
var entityName = "ccx_clientcaredoc";
// give the custom view a name
var viewDisplayName = "Related CDAs for " + patientName + "";
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
"<entity name='ccx_clientcaredoc'>" +
"<attribute name='ccx_clientcaredocid'/>" +
"<attribute name='ccx_name'/>" +
'<attribute name="createdon"/>' +
"<order attribute='ccx_name' descending='false'/> "+
"<filter type='and'>" +
"<condition attribute= 'ccx_client' operator='eq' value='[{7bfd140aaf-4df4-11dd-bd17-0019b9312238}]' /> "+
"</entity>" +
"</fetch>";
// build Grid Layout
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='ccx_clientcaredocid' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='ccx_clientcaredocid'>" +
"<cell name='ccx_name' " +
"width='250' />" +
"</row>" +
"</grid>";
// add the Custom View to the indicated [lookupFieldName] Control
Xrm.Page.getControl(lookupFieldName).addCustomView(defaultViewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
}
else {
// no Account selected, reset Contact Lookup View to the default view such that all Contacts are displayed for selection
Xrm.Page.getControl(lookupFieldName).setDefaultView(defaultViewId);
}
}
please provide some suggestion