首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubGrid fetchXML javascript刷新不显示链接实体列

SubGrid fetchXML javascript刷新不显示链接实体列
EN

Stack Overflow用户
提问于 2014-08-06 15:03:07
回答 1查看 1.5K关注 0票数 0

我在表单上有一个子网格,我试图根据表单数据使用动态fetchXML刷新。fetch正近似地刷新subGrid,但是链接实体列要么没有提取数据,要么subGrid没有显示数据。这是我正在运行的javascript。

代码语言:javascript
复制
    function UpdateContactSubGrid() {
    //If this method is called from the Onload, make sure the grid is loaded before proceeding
    if (document.getElementById('new_Opportunity_Contacts_SubGrid') == null) {
        //The subgrid hasn't loaded, wait 1 second and then try again 
        setTimeout(UpdateContactSubGrid, 1000);
        return;
    }    

    // To get the Id of the 'Contacts' subgrid
    var grid = document.getElementById('new_Opportunity_Contacts_SubGrid').control;  

    var fetchXML = "";

    // To get contract lookup from 'CustomerId' field 
    var accountLookup = getAttributeValue("customerid");

    if (accountLookup != null)
    {
         fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
         "<entity name='new_affiliation'>" +
          "<attribute name='new_role' />" +
          "<attribute name='new_contactid' />" +
          "<attribute name='new_affiliationid' />" +          
           "<order attribute='new_contactid' descending='false' />" +
           "<filter type='and'>" +
            "<condition attribute='statecode' operator='eq' value='0' /> " +
            "<condition attribute='new_clientid' operator='eq' value='" + accountLookup[0].id + "' />" +
           "</filter>" +
           "<link-entity name='contact' from='contactid' to='new_contactid' alias='a_adbe31a68306e2118bc478e3b5100e8d'>" +
           "<attribute name='emailaddress1' />" +
             "<attribute name='telephone1' />" +
             "<attribute name='mobilephone' />" +            
           "</link-entity>" +
         "</entity>" +
       "</fetch>";

    }
    else 
    {
        fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
         "<entity name='new_affiliation'>" +
          "<attribute name='new_role' />" +
          "<attribute name='new_contactid' />" +
          "<attribute name='new_affiliationid' />" +          
           "<order attribute='new_contactid' descending='false' />" +
           "<filter type='and'>" +
            "<condition attribute='statecode' operator='eq' value='0' /> " +
           "</filter>" +
           "<link-entity name='contact' from='contactid' to='new_contactid' alias='a_adbe31a68306e2118bc478e3b5100e8d'>" +
           "<attribute name='emailaddress1' />" +
             "<attribute name='telephone1' />" +
             "<attribute name='mobilephone' />" +            
           "</link-entity>" +
         "</entity>" +
       "</fetch>";
    }

    if (grid.SetParameter)
        //Inject the new fetchXml
        grid.SetParameter("fetchXml", fetchXML);
    else
        grid.get_innerControl().setParameter("fetchXml", fetchXML);

    //Force the subgrid to refresh
    grid.refresh();
}


// parametrs:
// attributeName: the name of the attribute  
//purpose:
//It checks the existance of the attribute on the form and then get the value of the attriute.It applies null checks.  
function getAttributeValue(attributeName) {
    try {
        var returnValue = null;
        var attrb = Xrm.Page.getAttribute(attributeName);
        if (attrb != null) {
            {
                var attrbValue = attrb.getValue();
                if (attrbValue != null)
                    returnValue = attrbValue;
            }
        }
        return returnValue;
    }
    catch (ex) {
        alert(ex.message + ' ' + ex.name);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-06 18:21:58

实体之间的关系类型是什么?使用N:N时,需要在链接实体节点中指示intersect="true“。使用N:1,您可以向链接实体节点添加链接类型=“外部”属性。

作为附带说明,请考虑动态编写FetchXml。

代码语言:javascript
复制
var fetchXML =
    fetch()
        .entity("new_affiliation")
            .attributes("new_role", "new_contactid", "new_affiliationid")
            .order("new_contactid", fetch.order.Asc)
            .filter()
                .condition("statecode", fetch.op.Equal, 0);

if (accountLookup != null) {
    fetchXML = fetchXML
        .condition("new_clientid", fetch.op.Equal, accountLookup[0].id);
}

fetchXML = fetchXML
    .link({
        entityName: "contact",
        to: "new_contactid",
        from: "contactid",
        alias : "a_adbe31a68306e2118bc478e3b5100e8d",
        type: fetch.link.outer //added outer join
    })
        .attributes("emailaddress1", "telephone1", "mobilephone")

return fetchXML.toString();

您可以在我的博客FetchXMl http://totbcrm.blogspot.com/2014/08/building-fetchxml-dynamically.html上找到有关使用动态http://totbcrm.blogspot.com/2014/08/building-fetchxml-dynamically.html构建器的更多信息。

HTH

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25163797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档