web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Issue with filtering exposure records based on associated account

(0) ShareShare
ReportReport
Posted on by
//Hello everyone,
In the /exposure records/=/relevé d'exposition/ section, I want to display only those that have the same associated account name as the one in /clientid/. I have written this code which seems to work correctly, as all the console.log messages are displayed as expected. However, nothing appears in the exposure records after the filter is applied. You can see the screenshots to see the issue. Here is the code I used:
 
 
function filterExpositions() {
    debugger;
    console.log(/DĂ©but du filtrage des relevĂ©s d'exposition./);
 
    // RĂ©cupĂ©rer l'ID du compte depuis le champ de recherche 'sfa_clientid'
    var accountLookup = Xrm.Page.getAttribute('sfa_clientid').getValue();
    var accountId = accountLookup ? accountLookup[0].id.replace('{', '').replace('}', '') : null;
    console.log(/ID du compte rĂ©cupĂ©rĂ© depuis le champ 'sfa_clientid':/, accountId);
 
    if (!accountId) {
        console.log(/Aucun ID de compte trouvĂ©, filtrage des relevĂ©s d'exposition non effectuĂ©./);
        return;
    }
 
    var expositionGrid = Xrm.Page.getControl('Subgrid_new_3');
    if (!expositionGrid) {
        console.log(/Grille de relevĂ© d'exposition non trouvĂ©e./);
        return;
    }
 
    // CrĂ©ation du FetchXML avec l'ID de compte dynamique pour le filtrage
    var fetchXml = /<fetch top='50'>/ +
                   /<entity name='sfa_relev'>/ +
                   /<attribute name='sfa_name' />/+
                  / <attribute name='sfa_famille4' />/+
                  / <attribute name='sfa_famille3' />/+
                  /<attribute name='sfa_famille2' />/+
                  / <attribute name='sfa_famille1' />/+
                  / <attribute name='sfa_famille5' />/+
                  / <attribute name='sfa_mise_en_place' />/+
                  / <attribute name='sfa_famille6' />/+
                  / <order attribute='sfa_mise_en_place' descending='true' />/+
                  / <attribute name='sfa_compte_to_releves' />/+
                  /<attribute name='ownerid' />/+
                  / <attribute name='sfa_relevid' />/+
                   /<link-entity name='account' from='accountid' to='sfa_compte_to_releves'>/ +
                   /<filter>/ +
                   /<condition attribute='accountid' operator='eq' value='/ + accountId + /' />/ +
                   /</filter>/ +
                   /</link-entity>/ +
                   /</entity>/ +
                   /</fetch>/;
    console.log(/FetchXML construit avec l'ID du compte dynamique:/, fetchXml);
 
    // Application du FetchXML Ă  la sous-grille et rafraĂ®chissement de celle-ci
    expositionGrid.setFilterXml(fetchXml);
    expositionGrid.refresh();
    console.log(/Grille de relevĂ© d'exposition rafraĂ®chie avec le nouveau filtre./);
 
    // RafraĂ®chissement du contrĂ´le 'Subgrid_new_3'
    var subGrid = Xrm.Page.getControl(/Subgrid_new_3/);
    if (subGrid) {
        subGrid.refresh();
        console.log(/ContrĂ´le 'subGrid' rafraĂ®chi./);
    } else {
        console.log(/ContrĂ´le 'subGrid' non trouvĂ©./);
    }
}
 
// Écouteur d'événements pour appeler filterExpositions lorsque le formulaire est chargé
document.addEventListener(/DOMContentLoaded/, function() {
    console.log(/Document chargĂ©, appel de filterExpositions./);
    filterExpositions();
});
 
and what i have in the consol:
Début du filtrage des relevés d'exposition.
ID du compte récupéré depuis le champ 'sfa_clientid': 15087B86-EDAB-EE11-BE37-000D3A28949E
sfa_owner:43 FetchXML construit avec l'ID du compte dynamique: <fetch top='50'><entity name='sfa_relev'><attribute name='sfa_name' /> <attribute name='sfa_famille4' /> <attribute name='sfa_famille3' /><attribute name='sfa_famille2' /> <attribute name='sfa_famille1' /> <attribute name='sfa_famille5' /> <attribute name='sfa_mise_en_place' /> <attribute name='sfa_famille6' /> <order attribute='sfa_mise_en_place' descending='true' /> <attribute name='sfa_compte_to_releves' /><attribute name='ownerid' /> <attribute name='sfa_relevid' /><link-entity name='account' from='accountid' to='sfa_compte_to_releves'><filter><condition attribute='accountid' operator='eq' value='15087B86-EDAB-EE11-BE37-000D3A28949E' /></filter></link-entity></entity></fetch>
sfa_owner:48 Grille de relevé d'exposition rafraîchie avec le nouveau filtre.
sfa_owner:54 Contrôle 'subGrid' rafraîchi.
 
 
I have the same question (0)
  • Suggested answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    You can try the following fetchXML.
    `<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="sfa_relev">
    <filter type="and">
    <condition attribute="accountid" operator="eq" value="${accountId}"/>
    </filter>
    </entity>
    </fetch>`
     
    You can refer to the following related links

    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     
  • Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    Has the issue been solved?
    Have there been any updates? Please feel free to ask me if you have any questions!
    If it has been resolved, can you mark the response as an answer?
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 165

#2
ManoVerse Profile Picture

ManoVerse 161 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans