CRM 2013 Javascript Filter Custom Lookup View Field (FetchXML)


Issues:

This part doesn't work when user click on lookup for more because i'm unable to set the default view fo the lookup. The user need to select the custom view by their own.

Script:

function FilterListingViewAidCategory(Value) {

    var RegistrationId = Xrm.Page.getAttribute("vwlzs_asnafcategory").getValue();
    if (RegistrationId == null && Value != null) {
        RegistrationId == Value;
    }
    var entityNumber = GetObjectTypeCode("vwlzs_aidsapplication");

    var FetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                      "<entity name='vwlzs_category'>" +
                        "<attribute name='vwlzs_categoryid' />" +
                        "<attribute name='vwlzs_name' />" +
                        "<attribute name='createdon' />" +
                        "<order attribute='vwlzs_name' descending='false' />" +
                        "<filter type='and'>" +
                          "<condition attribute='statecode' operator='eq' value='0' />" +
                          "<condition attribute='vwlzs_categoryasnaf' operator='in'>" +
                            "<value>" + RegistrationId + "</value>" +
                          "</condition>" +
                        "</filter>" +
                      "</entity>" +
                    "</fetch>";

    var layoutXml = "<grid name='resultset' object='10038' jump='vwlzs_name' select='1' preview='1' icon='1'>" +
                        "<row name='result' id='vwlzs_categoryid'>" +
                          "<cell name='vwlzs_name' width='300' />" +
                          "<cell name='createdon' width='150' />" +
                        "</row>" +
                      "</grid>";

    var viewId = guid();
    var viewDisplayName = "Filtered Based On Category";


    Xrm.Page.getControl("vwlzs_aidcategorylk").addCustomView(viewId, "vwlzs_category", viewDisplayName, FetchXML, layoutXml, true);
}


0 comments: