Dynamics 365 – Jscript/fetchXML问题:链接实体以过滤字段

huangapple go评论113阅读模式
英文:

Dynamics 365 - Issue with Jscript/fetchXML: linking entities for filtering a field

问题

我要创建的筛选器如下:我想要筛选位于我的表格(msdyn_customerasset)中的字段(uneeti_agreementinvoiceproduct)。筛选器必须满足以下条件:首先,合同的客户必须等于资产帐户。在我的fetchXML查询中,我将从我的表格(msdyn_agreementinvoiceproduct)中检索关联的合同表(msdyn_agreement)和字段(msdyn_serviceaccount)进行比较。其次,我只想显示已与合同资产相关联的产品。因此,我从我的表格(msdyn_customerasset)中检索我的产品字段,并从我的表格(msdyn_agreementinvoiceproduct)中提取(msdyn_product)。以下是我的检索查询,以及发生的错误。我不理解这个错误,因为指定的字段与指定的表格不相关。

错误

function filterProductContratFS(context) {

    var formContext = context.getFormContext();

    var fieldRecipientCall = formContext.getAttribute("msdyn_account").getValue();
    var fieldRecipientCall2 = formContext.getAttribute("msdyn_product").getValue();

    if (fieldRecipientCall && fieldRecipientCall2) {
        var accountId = fieldRecipientCall[0].id;
        var productId = fieldRecipientCall2[0].id;

        console.log(accountId);
        console.log(productId);

        var fetchXML =
            "<fetch>" +
            "<entity name='msdyn_agreementinvoiceproduct'>" +
            "<link-entity name='msdyn_agreement' from='msdyn_agreementid' to='msdyn_agreement'>" +
            "<filter>" +
            "<condition attribute='msdyn_serviceaccount' operator='eq' value='" + accountId + "' uitype='account'/>" +
            "</filter>" +
            "</link-entity>" +
            "<link-entity name='msdyn_customerasset' from='msdyn_customerassetid' to='msdyn_agreementinvoiceproductid'>" +
            "<filter>" +
            "<condition attribute='msdyn_product' operator='eq' value='" + productId + "' />" +
            "</filter>" +
            "</link-entity>" +
            "</entity>" +
            "</fetch>";

        var agreementInvoiceProductControl = formContext.getControl("uneeti_agreementinvoiceproduct");
        agreementInvoiceProductControl.addPreSearch(function () {
            agreementInvoiceProductControl.addCustomFilter(fetchXML);
        });

    } else {
        return;
    }
}

有人能帮我解决这个问题吗?

英文:

The filter I want to create is as follows: I want to filter a field (uneeti_agreementinvoiceproduct) located in my table (msdyn_customerasset). The filter must meet the following conditions: firstly, the customer of the contract must be equal to the asset account. In my fetchXML query from my table (msdyn_agreementinvoiceproduct), I will retrieve the linked contract table (msdyn_agreement) and the field (msdyn_serviceaccount) for comparison. Secondly, I want to display only the products that are already associated with the contract asset. Therefore, I retrieve my product field from my table (msdyn_customerasset) and fetch the (msdyn_product) from my table (msdyn_agreementinvoiceproduct). Here is my retrieval query, along with the error that is occurring. I don't understand this error because the specified field is not associated with the indicated table.

ERROR

function filterProductContratFS(context) {

var formContext = context.getFormContext();

var fieldRecipientCall = formContext.getAttribute(&quot;msdyn_account&quot;).getValue();
var fieldRecipientCall2 = formContext.getAttribute(&quot;msdyn_product&quot;).getValue();

if (fieldRecipientCall &amp;&amp; fieldRecipientCall2) {
    var accountId = fieldRecipientCall[0].id;
    var productId = fieldRecipientCall2[0].id;

    console.log(accountId);
    console.log(productId);

    var fetchXML =
        &quot;&lt;fetch&gt;&quot; +
        &quot;&lt;entity name=&#39;msdyn_agreementinvoiceproduct&#39;&gt;&quot; +
        &quot;&lt;link-entity name=&#39;msdyn_agreement&#39; from=&#39;msdyn_agreementid&#39; to=&#39;msdyn_agreement&#39;&gt;&quot; +
        &quot;&lt;filter&gt;&quot; +
        &quot;&lt;condition attribute=&#39;msdyn_serviceaccount&#39; operator=&#39;eq&#39; value=&#39;&quot; + accountId + &quot;&#39; uitype=&#39;account&#39;/&gt;&quot; +
        &quot;&lt;/filter&gt;&quot; +
        &quot;&lt;/link-entity&gt;&quot; +
        &quot;&lt;link-entity name=&#39;msdyn_customerasset&#39; from=&#39;msdyn_customerassetid&#39; to=&#39;msdyn_agreementinvoiceproductid&#39;&gt;&quot; +
        &quot;&lt;filter&gt;&quot; +
        &quot;&lt;condition attribute=&#39;msdyn_product&#39; operator=&#39;eq&#39; value=&#39;&quot; + productId + &quot;&#39; /&gt;&quot; +
        &quot;&lt;/filter&gt;&quot; +
        &quot;&lt;/link-entity&gt;&quot; +
        &quot;&lt;/entity&gt;&quot; +
        &quot;&lt;/fetch&gt;&quot;;

    var agreementInvoiceProductControl = formContext.getControl(&quot;uneeti_agreementinvoiceproduct&quot;);
    agreementInvoiceProductControl.addPreSearch(function () {
        agreementInvoiceProductControl.addCustomFilter(fetchXML);
    });

} else {
    return;
}}

Can someone help me resolve this issue?

答案1

得分: 0

你应该仔细检查一下addCustomFilter函数的工作方式。它只接受过滤器本身。所以不包括实体、链接实体等等。我知道唯一可能让它工作的方法是在这里描述的 - https://missdynamicscrm.blogspot.com/2014/08/crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity.html

英文:

You should doublecheck on how addCustomFilter function works. It accepts only filter itself. So no entity, not link-entity and so on. The only way I know you might make it works is described here - https://missdynamicscrm.blogspot.com/2014/08/crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity.html

huangapple
  • 本文由 发表于 2023年8月10日 22:40:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定