我有以下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;
}
});
}
答案 0 :(得分: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>";
答案 1 :(得分:1)
需要将XrmSvcToolkit添加为Web资源并在页面上引用。