Javascript CRM 2013:将记录添加到相关部分
我对crm 2013有意见。我将fetchXML用于过滤(例如)账单帐户。 当我们的团队与CRM 2011一起工作时,一切正常,但我们迁移到CRM 2013,在添加相关项目时遇到问题Javascript CRM 2013:将记录添加到相关部分,javascript,dynamics-crm-2013,fetchxml,Javascript,Dynamics Crm 2013,Fetchxml,我对crm 2013有意见。我将fetchXML用于过滤(例如)账单帐户。 当我们的团队与CRM 2011一起工作时,一切正常,但我们迁移到CRM 2013,在添加相关项目时遇到问题 retrieveRecord( recordId, "xxx_project", null, null, function (result) {
retrieveRecord(
recordId,
"xxx_project",
null,
null,
function (result) {
var xId = (result.xxx_Customer) ? result.xxx_xCustomer : "";
// Fetch to retrieve filtered data.
var fetch =
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='xxx_billingaccount'>" +
" <attribute name='xxx_billingaccountid' />" +
" <attribute name='xxx_name' />" +
" <attribute name='statecode' />" +
" <attribute name='xxx_xid' />" +
" <order attribute='xxx_name' descending='false' />" +
" <filter type='and'>" +
" <condition attribute='xxx_xid' operator='eq' value='" + xId + "' />" +
" </filter>" +
" </entity>" +
"</fetch>";
// Columns to display in the custom view (make sure to include these in the fetch query).
var layout = "<grid name='resultset' object='1' jump='xxx_name' select='1' icon='0' preview='1'>" +
" <row name='result' id='xxx_billingaccountid'>" +
" <cell name='xxx_name' width='150' />" +
" <cell name='statecode' width='150' />" +
" <cell name='xxx_xid' width='150' />" +
" </row>" +
"</grid>";
SDK.Entity.BillingAccount.displayFilteredLookupView(gridTypeCode, gridControl, fetch, layout, "Filtered by Customer ID Billing Accounts");
},
SDK.Entity.BillingAccount.errorHandler);
当我搜索解决此问题的路径时,我找到了一个链接。这对我们的项目来说是非常糟糕的
也许有人可以帮我解决这个问题…您应该将
LookupObjects
函数更改为LookupObjectsWithCallback
函数:
LookupObjectsWithCallback(callbackReference, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView], null, null, null, null, null, null, 1);
并在代码中调用它,如下所示:
displayFilteredLookupView: function (gridTypeCode, gridControl, fetch, layout, viewName) {
var viewId = "{3D02B064-4D8D-4E7C-B919-965D5D2C225D}";
var relName = gridControl.GetParameter("relName"),
roleOrd = gridControl.GetParameter("roleOrd");
// Creates the custom view object.
var customView = {
fetchXml: fetch,
id: viewId,
layoutXml: layout,
name: viewName,
recordType: gridTypeCode,
Type: 0
};
// Get all necessary parameters, that you want to pass into your callbackReference function.
SDK.Entity.BillingAccount.callbackReference.gridTypeCode = gridTypeCode;
SDK.Entity.BillingAccount.callbackReference.relName = relName;
SDK.Entity.BillingAccount.callbackReference.roleOrd = roleOrd;
// Pops the lookup window with our view injected.
LookupObjectsWithCallback(SDK.Entity.BillingAccount.callbackReference, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView], null, null, null, null, null, null, 1);
}
其中,SDK.Entity.BillingAccount.callbackReference
是一个具有属性的对象,callback
,gridTypeCode
,roleOrd
,relName
:
callbackReference: {
callback: function (lookupItems) {
// Once the lookup window is closed, we need the parent record ID and ETC before associating selected records.
if (lookupItems && lookupItems.items.length > 0) {
var parent = GetParentObject(),
parentId = parent.id,
parentTypeCode = parent.objectTypeCode;
//associates the selected records
AssociateObjects(parentTypeCode, parentId, SDK.Entity.BillingAccount.callbackReference.gridTypeCode, lookupItems, IsNull(SDK.Entity.BillingAccount.callbackReference.roleOrd) || SDK.Entity.BillingAccount.callbackReference.roleOrd == 2, "", SDK.Entity.BillingAccount.callbackReference.relName);
}
},
gridTypeCode: null,
roleOrd: null,
relName: null
}
我无法提出上述建议来工作。我认为这是因为我不了解如何定义对象“callbackReference”。当我按照上面的文档粘贴代码时,VisualStudio会抱怨。下面是代码,它不起作用
var locAssocObjAction1 = {
callback: function (lookupItems) {
//debugger;
// Once the lookup window is closed, we need the parent record ID and ETC before associating selected records.
if (lookupItems && lookupItems.items.length > 0) {
var parent = GetParentObject(),
parentId = parent.id,
parentTypeCode = parent.objectTypeCode;
//associates the selected records
AssociateObjects(parentTypeCode, parentId, params.gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
}
Xrm.Utility.alertDialog("Message on alert dialog", function () { });
}
}
//pops the lookup window with our view injected
LookupObjectsWithCallback(locAssocObjAction1, null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
作为解决办法,我找到了以下解决方案:
上述建议与Paul Niewelaar建议的主要区别如下
var callbackRef = Mscrm.Utilities.createCallbackFunctionObject("locAssocObjAction", this, parameters, false);
//pops the lookup window with our view injected
LookupObjectsWithCallback(callbackRef, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
}
我不确定“locAssocObjAction”的实施情况。然而,N:N协会似乎起了作用
干杯
var callbackRef = Mscrm.Utilities.createCallbackFunctionObject("locAssocObjAction", this, parameters, false);
//pops the lookup window with our view injected
LookupObjectsWithCallback(callbackRef, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);