Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Add new filter on a personal view using JavaScript

(0) ShareShare
ReportReport
Posted on by 2
Hi,
 
Is it possible to add new filter on a personal view using JavaScript?
I'm using D365 CE. Thank you in advance.
  • Inogic Profile Picture
    Inogic 438 on at
    Add new filter on a personal view using JavaScript
    Hi,
     
    Yes, you can add a filter condition in the personal view. Please find the below code to add a filter in fetchXml of personal view using javascript. The below function will return fetch XML which contains the filter condition which we have added. After successfully returning fetchXml you can directly execute the fetchXml using Web API.

    var addFilterInFetchXML = function () {
        var filterXML = '';
       var fetchXml = "";
        try {
           //prepare existing  fetchXML       
            fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
            "<entity name='account'>"+
            "<attribute name='name'/>"+
            "<attribute name='telephone1'/>"+
            "<attribute name='address1_city'/>"+
            "<attribute name='primarycontactid'/>"+
            "<attribute name='statecode'/>"+
            "<link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer'    alias='accountprimarycontactidcontactcontactid'>"+
            "<attribute name='emailaddress1'/>"+
            "</link-entity>"+
            "</entity>"+
            "</fetch>";

            //covert fetchXML string to XML
            fetchXml = $.parseXML(fetchXml);

            //prepare filter condition as per your requirement
            filterXML += "<filter type='and'> <condition attribute='industrycode' operator='eq' value='1'>";
            filterXML += "</condition> </filter>";   

            //add filter condition into actual fetchXML
            $(fetchXml).find('entity').append(filterXML);

            //convert XML into a string (fetchXML string)
            fetchXml = (new XMLSerializer()).serializeToString($(fetchXml)[0]);
        }
        catch (e) {
            throw new Error(e);
        }
          //return updated fetchXML which contains filter condition
       return fetchXml;
    }
     
    Hope this helps.
     
    Thanks!

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans