以下是我们如何在 v9.1 系统中过滤 UCI 和旧版 UI 中的查找的本质:
//Legacy UI uses custom views, UCI only custom filters
views.push({
id: '{' + getRandomGuid().toUpperCase() + '}',
fetchXml: '' +
'<fetch mapping="logical" distinct="true" version="1.0">' +
'<entity name="product">' +
'<attribute name="productid" />' +
'<attribute name="productnumber" />' +
'<attribute name="name" />' +
'<attribute name="description" />' +
'<order attribute="productnumber" descending="false" />' +
'<filter type="and">' +
'<condition attribute="new_pricelevelid" operator="eq" value="' + myGuid + '" />' +
'</filter>';
'</entity>' +
'</fetch>',
layoutXml: '' +
'<grid name="resultset" object="' + productTypeCode + '" jump="name" select="0" icon="0" preview="0">' +
'<row name="result" id="productid">' +
'<cell name="name" width="125" />' +
'<cell name="description" width="400" />' +
'</row>' +
'</grid>',
name: 'Custom Product View',
recordType: productTypeCode,
Type: "0"
});
var CustomFilter = '<filter type="and">' +
'<condition attribute="new_pricelevelid" operator="eq" value="' + myGuid + '" />' +
'</filter>';
try {
var lookupParameters = {};
lookupParameters.entityTypes = ['quote'];
lookupParameters.defaultEntityType = 'quote';
//lookupParameters.defaultViewId = views[0].id;
lookupParameters.allowMultiSelect = false;
//Xrm.Internal.isUci() is unsupported!
if (Xrm.Internal.isUci() ) {
//Filter on UCI
if (CustomFilter != null) {
lookupParameters.filters = [{ filterXml: CustomFilter }];
}
}
else {
//Filter on Legacy UI
lookupParameters.customViews = [views[0]];
lookupParameters.viewIds = [views[0].id];
lookupParameters.defaultViewId = views[0].id;
}
//Use OOB CRM lookup w/ Custom Filter.
Xrm.Utility.lookupObjects(lookupParameters).then(
function (selectedItems) {
callback.call(scope, ifNull(selectedItems, []));
},
function (error) {
if (error != null) {
Xrm.Utility.alertDialog(error.message);
}
});
}
catch (e) {
Xrm.Utility.alertDialog(e.message);
}
请注意,为了简单和隐私,我修改了此代码。我没有以目前的形式对其进行测试。