2

我有以下 fetchXML 代码用于返回相关实体的总数。主要实体名称为new_transaction,相关实体名称为new_transactionproduct

下面的代码放置在 web 资源 javascript 中,但是当调用此函数时,它永远不会成功或错误部分,它只是挂起。

 function countLineItems()
 {
 var ID = Xrm.Page.data.entity.getId();
 var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>";
 fetchXml += "<entity name='new_transactionproduct'>";
 fetchXml += "<attribute name='new_name' alias='recordcount' aggregate='countcolumn' />";
 fetchXml += "<filter type='and'>";
 fetchXml += "<condition attribute='new_transactionid' operator='eq' value='" + ID + "' />";
 fetchXml += "</filter>";
 fetchXml += "</entity>";
 fetchXml += "</fetch>";
 alert(fetchXml);
 XrmSvcToolkit.fetch({
        fetchXml: fetchXml,
        async: false,
        successCallback: function (result) {
            var countValue =  result.entities[0].recordcount;
 alert(countValue);
    //Xrm.Page.getAttribute(new_totalqty).setValue(countValue);
        },
        errorCallback: function (error) {
            throw error;
        }
 });
 }
4

2 回答 2

2

只是一个快速的旁注,你总是可以像下面这样设置你的 fetchXML 来最小化你附加到字符串的次数。

string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
                        <entity name='new_transactionproduct'>
                             <attribute name='new_name' alias='recordcount' aggregate='countcolumn' />
                               <filter type='and'>
                                 <condition attribute='new_transactionid' operator='eq' value='" + ID + @"' />
                               </filter>
                        </entity>
                    </fetch>";
于 2013-03-22T10:49:05.267 回答
1

XrmSvcToolkit 需要作为 Web 资源添加并在页面上引用。

于 2013-03-21T23:27:28.613 回答