我正在尝试获取与Invoiceline实体链接的Invoices实体,但没有结果

时间:2019-06-30 17:53:45

标签: javascript dynamics-365 fetchxml

当我仅使用属性时,我的提取工作正常,但是当我添加链接实体或进行过滤时,它不起作用。这是链接代码。请帮助找到我的错误!

这两个实体与发票中的名称字段和发票行中的发票字段相关。

    var fetchInvoices = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">';
        fetchInvoices += '<entity name="hms_invoice">';
        fetchInvoices += '<attribute name="hms_name"/>';
        fetchInvoices += '<attribute name="hms_customer" />';
        fetchInvoices += '<link-entity name="hms_invoiceline" from="hms_invoice" to="hms_name">';
        fetchInvoices += '<attribute name="hms_amount" />';
        fetchInvoices += '</link-entity>';
        fetchInvoices += '</entity>';
        fetchInvoices += '</fetch>';

    var invoices = XrmServiceToolkit.Soap.Fetch(fetchInvoices);
    alert(invoices.length);

我需要从发票中获取名称和客户,并从发票行中获取金额。

1 个答案:

答案 0 :(得分:0)

我将避免使用Microphone.h表单,因为您必须添加第三方库才能使用它,并且最新版本不支持SOAP,相反,我建议使用Webapi,因为这是支持的方式和最简单的数据获取方式

这里的链接将为您提供D365 crm中的Webserevice呼叫详细信息。

以下,我尝试获取特定帐户ID的所有联系人, 例如:帐户A有3个与之关联的联系人,而我要提取所有3个联系人。

这是示例代码。

XrmServiceToolkit.Soap.Fetch

还有一种使用以下较小代码调用webapi的全新方法

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts?$select=_accountid_value,contactid,fullname&$filter=_accountid_value eq 4930FC98-5F75-E911-A83C-000D3A385DD4", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var results = JSON.parse(this.response);
            for (var i = 0; i < results.value.length; i++) {
                var _accountid_value = results.value[i]["_accountid_value"];
                var _accountid_value_formatted = results.value[i]["_accountid_value@OData.Community.Display.V1.FormattedValue"];
                var _accountid_value_lookuplogicalname = results.value[i]["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
                var contactid = results.value[i]["contactid"];
                var fullname = results.value[i]["fullname"];
            }
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();
相关问题