Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 2

Hello everyone,

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.

Can someone help me resolve this issue ?

JS : 

    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;
    }}

Error : 

//////////

  • Community member Profile Picture
    2 on at
    Dynamics 365 - Issue with Jscript/fetchXML: linking entities for filtering a field
    The problem is solved. Here is a useful link for those who encounter the same problem.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,110 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans