我有以下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;
}
});
}发布于 2013-03-21 23:27:28
XrmSvcToolkit需要作为web资源添加并在页面上引用。
发布于 2013-03-22 10:49:05
只需简单说明一下,您就可以像下面这样设置您的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>";https://stackoverflow.com/questions/15554668
复制相似问题