CRM 2013 Javascript N:N AssociateObjects not working

CRM 2013 Javascript N:N AssociateObjects not working

本文关键字:not working AssociateObjects Javascript CRM 2013      更新时间:2023-09-26

我们正在从CRM 2011迁移到CRM 2013,两者都是本地版本。我们使用javascript在Case表单上定制了一个功能区,它加载了N:N关联的Account实体的自定义Lookup视图。从这个自定义查找视图中,用户可以将所选Account记录与当前Case关联起来。

由于某些原因,这个函数在crm 2013中不再工作了。自定义Lookup视图仍然正确加载,但是由于某些原因,Account记录不再与父Case记录相关联。

我读了另一个关于这个问题的问题,这个问题是由Paul Nieuwelaar通过下面的链接解决的:http://www.magnetismsolutions.co.nz/blog/paulnieuwelaar/2014/04/21/filter - n - n -添加-现有-查找-动力学- crm - 2013

基本上' LookupObjects '功能在CRM 2013中不再工作,必须由' LookupObjectsWithCallback '取代。

然而,即使遵循此解决方案,我仍然无法将帐户记录关联到Case。下面是我按照Paul Nieuwelaar的建议修改的代码。我遗漏了什么吗?为了以防万一,我甚至在代码中包含了CRM 2011版本是否仍在使用Rollup 12。我有一种感觉,这可能是因为父Case在脚本中没有被正确地拾取。

非常感谢你的帮助。

伊丽莎白

function openAddLookupDialog(gridTypeCode) {
var relName = "new_account_incident";
var roleOrd = 2;
var viewId = "{00000000-0000-0000-00AA-000010001002}"; //dummy view ID
if (!IsNull(relName)) {
    var customView = {
        fetchXml: "{...}", //my FetchXML
        id: viewId,
        layoutXml: "{...}", //my layoutXml
        name: "Filtered Lookup View",
        recordType: gridTypeCode,
        Type: 0
    };
    var parent = GetParentObject(null, 0);
    var parameters = [gridTypeCode, "", relName, roleOrd, parent];
    var callbackRef = Mscrm.Utilities.createCallbackFunctionObject("locAssocObjAction", this, parameters, false);
    //pops the lookup window with our view injected
    var lookupItems = LookupObjectsWithCallback(callbackRef, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
}
if (lookupItems && lookupItems.items.length > 0) {
    //beginning of rollup 12 must make modification
    var parentId;
    var parentTypeCode;
    if (typeof (GetParentObject) == "function") { //post rollup 12 has its own function to get this 
        var parent = GetParentObject();
        parentId = parent.id;
        parentTypeCode = parent.objectTypeCode;
    }
    else { //pre rollup 12 still needs to use the old way 
        var parent = typeof (crmFormSubmit) == "undefined" ? $get("crmFormSubmit") : crmFormSubmit; 
        //according to daniels blog crmFormSubmit should already be defined, but it's not... 
        if (parent) {
            parentId = parent.crmFormSubmitId.value;
            parentTypeCode = parent.crmFormSubmitObjectType.value;
        }
        else {
            parentId = window.parent.crmFormSubmit.crmFormSubmitId.value;
            parentTypeCode = window.parent.crmFormSubmit.crmFormSubmitObjectType.value;
        }
    }//end of rollup 12 modification
    //both of AssociateObjects that I try below here don't work
    //AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
    AssociateObjects(parentTypeCode, parentId, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);

}

}

我们还修改了customize .xml文件,使其在单击按钮时触发javascript。

<CommandDefinition Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command">
        <EnableRules>
          <EnableRule Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command.EnableRule.FormStateRule" />
          <EnableRule Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command.EnableRule.ValueRule" />
        </EnableRules>
        <DisplayRules />
        <Actions>
          <JavaScriptFunction FunctionName="openAddLookupDialog" Library="$webresource:new_account_incident.js">
            <IntParameter Value="1" />
          </JavaScriptFunction>
        </Actions>

供您参考,上面的代码正在工作!不工作的是应该刷新子网格的代码的某些部分……还是故障排除