51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

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

英文:

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

问题 {#heading}

我要创建的筛选器如下:我想要筛选位于我的表格(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 =
        &amp;quot;&amp;lt;fetch&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;entity name=&amp;#39;msdyn_agreementinvoiceproduct&amp;#39;&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;link-entity name=&amp;#39;msdyn_agreement&amp;#39; from=&amp;#39;msdyn_agreementid&amp;#39; to=&amp;#39;msdyn_agreement&amp;#39;&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;filter&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;condition attribute=&amp;#39;msdyn_serviceaccount&amp;#39; operator=&amp;#39;eq&amp;#39; value=&amp;#39;&amp;quot; + accountId + &amp;quot;&amp;#39; uitype=&amp;#39;account&amp;#39;/&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/filter&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/link-entity&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;link-entity name=&amp;#39;msdyn_customerasset&amp;#39; from=&amp;#39;msdyn_customerassetid&amp;#39; to=&amp;#39;msdyn_agreementinvoiceproductid&amp;#39;&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;filter&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;condition attribute=&amp;#39;msdyn_product&amp;#39; operator=&amp;#39;eq&amp;#39; value=&amp;#39;&amp;quot; + productId + &amp;quot;&amp;#39; /&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/filter&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/link-entity&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/entity&amp;gt;&amp;quot; +
        &amp;quot;&amp;lt;/fetch&amp;gt;&amp;quot;;

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



`} else {
return;
}}
`

Can someone help me resolve this issue?

答案1 {#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


赞(1)
未经允许不得转载:工具盒子 » Dynamics 365 – Jscript/fetchXML问题:链接实体以过滤字段