CRM 2013查找中的addCustomView

时间:2014-09-03 10:39:36

标签: javascript dynamics-crm dynamics-crm-2013

当我将自定义视图设置为CRM 2013团队查找时,我得到一个 Savedquery,其中ID = 00000000-0000-0000-0000-000000000000不存在消息,请使用此代码, CRM 2011。

// Set the Owning Team View based on the account selected
function setOwningTeamView(entityFieldName, lookupFieldName, resetSelection) {
  // Get the selected entity 
  var account = Xrm.Page.getAttribute(entityFieldName).getValue();

if (account != null) {
    var accid = account[0].id;
    var accname = account[0].name;

    if (resetSelection == true) {
        // reset old selection for Contact
        Xrm.Page.getAttribute(lookupFieldName).setValue(null);
    }

    // use randomly generated GUID Id for the view
    var viewId = "{0CBC820C-7033-4AFF-9CE8-FB610464DBD3}";
    var entityName = "team";

    // give the custom view a name
    var viewDisplayName = "Teams applicable to " + accname + "";

    var accountBU = SDK.REST.retrieveRecordSync(Xrm.Page.getAttribute("a_account").getValue()[0].id, "Account", "OwningBusinessUnit", "");
    var relatedBusinessUnits = SDK.REST.retrieveMultipleRecordsSync("BusinessUnit", "?$select=BusinessUnitId,Name&$filter=a_Type/Value eq 1");
    var FetchXMLBU = "";
    for (var i = 0; i < relatedBusinessUnits.results.length; i++) {
        FetchXMLBU += "<value>" + relatedBusinessUnits.results[i].BusinessUnitId + "</value>"
    }

    debugger;

    // find all contacts where parent customer is the account selected and where the Contact record is active
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
        + "<entity name='team'>"
        + "<attribute name='teamid' />"
        + "<attribute name='name' />"
        + "<attribute name='description' />"
        + "<attribute name='businessunitid' />"
        + "<filter>"
        + "<condition attribute='businessunitid' operator='in'>"
        + "<value>" + accountBU.OwningBusinessUnit.Id + "</value>"
        + FetchXMLBU
        + "</condition>"
        + "</filter>"
        + "</entity>"
        + "</fetch>";

    // build Grid Layout
    var layoutXml = "<grid name='resultset' " +
        "object='1' " +
        "jump='teamid' " +
        "select='1' " +
        "icon='0' " +
        "preview='0'>" +
        "<row name='result' id='teamid'>" +
        "<cell name='name' width='200' />" +
        "<cell name='businessunitid' width='200' />" +
        "<cell name='description' width='400' />" +
        "</row>" +
        "</grid>";

    // add the Custom View to the indicated [lookupFieldName] Control
    Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
    //The following line is the an unsupported way of disabling the View Picker, currently there is no supported way.
    document.getElementById(lookupFieldName + "_i").setAttribute("disableViewPicker", "1");
    //document.getElementById(lookupFieldName).setAttribute("disableViewPicker", "1");
}
}

我怀疑问题是{strong> SDK.REST 的调用问题in this thread,但导致 accountBU relatedBusinessUnits 是正确的。

我使用另一个SDK调用,但行为正确:

 var systemUserTeam = SDK.REST.retrieveMultipleRecordsSync("TeamMembership",
                "$select=TeamId&$filter=TeamId eq guid'"
                + Xrm.Page.getAttribute("aux_owningteamid").getValue()[0].id
                + "' and SystemUserId eq guid'"
                + Xrm.Page.getAttribute("ownerid").getValue()[0].id
                + "'");
    if (systemUserTeam.results.length != 1) {

我正在使用自定义 fetchXML laoyoutXML 设置客户查找视图,方法外对SDK的调用。

我可以对SDK调用进行哪些​​更改以使其正常工作?

3 个答案:

答案 0 :(得分:2)

如果您不反对重写代码,那么现在可以更轻松,更受支持地为查询添加自定义过滤器。您可以使用现有视图并应用preFilter。

This blog post提供了一个很好的例子。

答案 1 :(得分:1)

addCustomView不适用于Owner次查找。 Owner次查找用于分配用户拥有的记录。

链接 - https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_addCustomView

答案 2 :(得分:0)

可能是对象=&#39; 1&#39;在layoutxml- objecttypecode为1表示您正在尝试在帐户上创建视图,当您需要在团队中创建它时。因此,CRM正在针对帐户制作自定义视图,并且他们试图将其称为针对团队。团队我相信是9.这个改变应该有希望其他一切都是正确的,你有没有排序。如果不是九,请下载并安装DynamicsXRMtools解决方案并检查CRM元数据。