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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set up custom fetchXML for Subgrid in Dynamics CRM

(0) ShareShare
ReportReport
Posted on by 3,634

I have following fetchXML that I need to set up for a subgrid on Invoice form. I s there any idea how it can be achieved in supported way?

var orderId = Xrm.Page.getAttribute("salesorderid").getValue()[0].id;
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                    "  <entity name='systemuser'>" +
                    "    <attribute name='fullname' />" +
                    "    <attribute name='businessunitid' />" +
                    "    <attribute name='title' />" +
                    "    <attribute name='address1_telephone1' />" +
                    "    <attribute name='positionid' />" +
                    "    <attribute name='systemuserid' />" +
                    "    <order attribute='fullname' descending='false' />" +
                    "    <link-entity name='new_salesorder_systemuser' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
                    "      <link-entity name='salesorder' from='salesorderid' to='salesorderid' alias='ab'>" +
                    "        <filter type='and'>" +
                    "          <condition attribute='salesorder' operator='eq' value='" + orderId + "' />" +
                    "        </filter>" +
                    "      </link-entity>" +
                    "    </link-entity>" +
                    "  </entity>" +
                    "</fetch>";



*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    Hi Mohsin,

    Follow this link:-

    blogs.msdn.microsoft.com/.../filtering-in-sub-grids-crm-2015-crm-online

    https://community.dynamics.com/crm/f/117/t/164732

  • Mohsin Ali Profile Picture
    3,634 on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    'SetParameter' is undefined.

  • Suggested answer
    Community Member Profile Picture
    on at
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    Hi,

    Try this too..

    social.microsoft.com/.../trying-to-set-subgrid-fetchxml-with-subgrid1controlsetparameterfetchxml-fetchxml

    Thanks..

  • Verified answer
    Mohsin Ali Profile Picture
    3,634 on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    I achieve this using Quick View form. Everything else throw the exception, so QVF worked for me.

  • Suggested answer
    Silent Serenity Profile Picture
    55 on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    Hi Mohsin,

    For D365 CRM V.9 I used this code below, Assuming you already set up the subgrid in the form as "All related records":

    function FetchViaName(executionContext) {

       var formContext = executionContext.getFormContext();

       // Credit_Performance : is name of subgrid given on Form.

       // You need the code below because using SetParameter in formContext.getControl("Credit_Performance") will not work.

       var objSubGrid = window.parent.document.getElementById("Credit_Performance");

       var conSubGrid = formContext.getControl("Credit_Performance");

       var subRowCount = conSubGrid.getGrid().getTotalRecordCount(); // Making sure that you the grid is loaded

       var formContext = executionContext.getFormContext();

       var globalContext = Xrm.Utility.getGlobalContext();

       var version = globalContext.getVersion();

       // You need the timeout for at least the form is properly loaded.

       if (subRowCount == 0) {

           setTimeout(FetchViaName(executionContext), 5000);

       } else {

           // When subgrid is loaded, get the other relevant value.

           var curId = formContext.data.entity.getId();

           var curName = formContext.getAttribute("dxcts_name").getValue();

           var ratingName = formContext.getAttribute("dxcts_searchratingname").getValue();

           var workAccount = formContext.getAttribute("dxcts_workaccount").getValue();

           //Create FetchXML for sub grid to filter records

           var FetchXml = '<fetch version="1.0" output-format="xml - platform" mapping="logical" distinct="false"> '

               + '<entity name = "dxcts_creditperformance" > '

               + '<attribute name="dxcts_creditperformanceid" /> '

               + '<attribute name="dxcts_name" /> '

               + '<attribute name="dxcts_work" /> '

               + '<attribute name="dxcts_ratings" /> '

               + '<attribute name="dxcts_comments" /> '

               + '<attribute name="dxcts_sugestions" /> '

               + '   <attribute name="createdon" /> '

               + '   <order attribute="dxcts_name" descending="false" /> '

               + '   <filter type="and"> '

               + '       <condition attribute="dxcts_work" operator="eq" uiname="' + curName + '" uitype="dxcts_work" value="' + curId + '" /> '

               + '       <condition attribute="dxcts_accountscreditperformanceid" operator="eq" uiname="' + workAccount[0].name + '" uitype="account" value="' + workAccount[0].id + '" /> '

               + '       <condition attribute="statuscode" operator="eq" value="1" /> '

               + '       <condition attribute="dxcts_name" operator="like" value="%' + ratingName + '%" />'

               + '   </filter> '

               + ' </entity > '

               + ' </fetch > ';

           // Layout of subgrid. It's up to you if your going to use this code, it's just creating/identifying a new layout.

           //var LayoutXml = "<grid name='resultset' object='8' jump='new_name' select='1' preview='1' icon='1'>" +

           //    " <row name='result' id='new_boat'>" +

           //    "<cell name='dxcts_name' width='100' />" +

           //    "<cell name='dxcts_work' width='200' />" +

           //    "<cell name='dxcts_ratings' width='100' />" +

           //    "<cell name='dxcts_comments' width='200' />" +

           //    "<cell name='dxcts_sugestions' width='200' />" +

           //    "</row>" +

           //    "</grid>";

           // Apply layout and filtered fetchXML

           //objSubGrid.control.SetParameter("layoutXml", LayoutXml);

           objSubGrid.control.SetParameter("fetchXml", FetchXml);

           //Refresh grid to show filtered records only.

           objSubGrid.control.Refresh();

       }

    }

    Happy Coding! =D

  • Community Member Profile Picture
    on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    Please follow the Link, I have done this in my project and it is working, do like the link page and mark the answer correct.

    https://sank8sinha.wordpress.com/2020/01/07/adding-filtered-views-in-uci-in-dynamics-365-crm-finally-achieved/

  • RHOU Profile Picture
    65 on at
    RE: How to set up custom fetchXML for Subgrid in Dynamics CRM

    I just created a very detailed feature wish to make this happen in a supported way for Unified Interface here:

    PLEASE VOTE!

    powerusers.microsoft.com/.../675538

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Wayne Walton Profile Picture

Wayne Walton 2

#2
Good.Panos Profile Picture

Good.Panos 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans