Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Issue with filtering exposure records based on associated account

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.
 
 
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Issue with filtering exposure records based on associated account
    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?
     
  • Suggested answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Issue with filtering exposure records based on associated account
    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
     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans