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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

bind fetch xml data to grid and refresh . crm 2016 online

(0) ShareShare
ReportReport
Posted on by 382

H all, 

I have to bind fetch xml results and bind data to grid and refresh it . it couldn't happen .

code below 

$(document).ready(function FilterConnectionSubgrid()
{
var ConnectionSubgrid =document.getElementById("OpportunityCurrentFiscalYear");
if(ConnectionSubgrid==null)
{
setTimeout(function () { FilterConnectionSubgrid(); }, 2000); //if the grid hasn’t loaded run this again
return;
}

var fetchXml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
fetchXml += "<entity name='bis_projectbusinessunit'>"
fetchXml += "<attribute name='bis_name'/>"
fetchXml += "<attribute name='bis_project'/>"
fetchXml += "<attribute name='bis_keyaccount'/>"
fetchXml += "<attribute name='bis_estrevenue_base'/>"
fetchXml += "<attribute name='bis_estrevenue'/>"
fetchXml += "<attribute name='bis_estawarddate'/>"
fetchXml += "<attribute name='bis_businessunit'/>"
fetchXml += "<attribute name='bis_projectbusinessunitid' />"
fetchXml += "<order attribute='bis_name' descending='false'/>"
fetchXml += "<filter type='and'>"
fetchXml += "<filter type='or'>"
fetchXml += "<condition attribute='bis_competitor' operator='eq' uitype='competitor' value='" + Xrm.Page.data.entity.getId() + "'/>"
fetchXml += "<condition attribute='bis_competitor2' operator='eq' uitype='competitor' value='" + Xrm.Page.data.entity.getId() + "'/>"
fetchXml += "<condition attribute='bis_competitor3' operator='eq' uitype='competitor' value='" + Xrm.Page.data.entity.getId() + "'/>"
//fetchXml += "<condition attribute='bis_competitor' operator='eq' uiname='Alaska' uitype='competitor' value='{A576591D-EDEB-E411-80F3-C4346BACBF08}' />"
fetchXml += "</filter>"
fetchXml += "</filter>"
fetchXml += "</entity>"
fetchXml += "</fetch>"
//Set the fetchxml directly to subgrid

ConnectionSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid

ConnectionSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
});

please advice .

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Refer the below working code:

    Refer below working code:
    
    function FundedSupportsSubGrid(){
    		var grid = parent.document.getElementById('Funded_Supports');
            var clientContact = common.getValue('rsa_client_contact');
            if (grid == null || grid.control == null) {
                setTimeout('FundedSupportsSubGrid();', 500);
            } else {
                var fetchXml = [];
                if (clientContact) {
    				var today = common.getSystemDate();
                    var date = "";
                    var month = "";
                    if ((today.getDate()) < 10) {
                        date = "0" + new Date().getDate();
                    }
                    else {
                        date = today.getDate();
                    }
                    if ((today.getMonth() + 1) < 10) {
                        month = "0" + (today.getMonth() + 1);
                    }
                    else {
                        month = (today.getMonth() + 1);
                    }
                    var planExpiryDate = today.getFullYear() + "-" + month + "-" + date;
    				
                    fetchXml.push('<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">');
                    fetchXml.push('<entity name="rsa_ndis_plan_support">');
                    fetchXml.push('<attribute name="rsa_unit_of_measure" />');
                    fetchXml.push('<attribute name="rsa_refund_amount_per_unit" />');
    				fetchXml.push('<attribute name="rsa_number_of_units_provided" />');
                    fetchXml.push('<attribute name="rsa_effective_date_to" />');
    				fetchXml.push('<attribute name="createdon" />');
                    fetchXml.push('<attribute name="rsa_supports_from_funding_item_description" />');
    				fetchXml.push('<attribute name="rsa_ndis_plan_supportid" />');
                    fetchXml.push('<order attribute="createdon" descending="true" />');
                    fetchXml.push('<filter type="and">');
                    fetchXml.push('<condition attribute="rsa_client_contact" operator="eq"  value="' + clientContact.id + '" />');
                    fetchXml.push('<condition attribute="rsa_effective_date_to" operator="on-or-after" value="' + planExpiryDate + '" />');
                    fetchXml.push('</filter>');
                    fetchXml.push('</entity>');
                    fetchXml.push('</fetch>');
                } else {
                    fetchXml.push('<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">');
    				fetchXml.push('<entity name="rsa_ndis_plan_support">');
                    fetchXml.push('<attribute name="rsa_unit_of_measure" />');
                    fetchXml.push('<attribute name="rsa_refund_amount_per_unit" />');
    				fetchXml.push('<attribute name="rsa_number_of_units_provided" />');
                    fetchXml.push('<attribute name="rsa_effective_date_to" />');
    				fetchXml.push('<attribute name="createdon" />');
                    fetchXml.push('<attribute name="rsa_supports_from_funding_item_description" />');
    				fetchXml.push('<attribute name="rsa_ndis_plan_supportid" />');
                    fetchXml.push('<order attribute="createdon" descending="true" />');
                    fetchXml.push('<filter type="and">');
                    fetchXml.push('<condition attribute="createdon" operator = "yesterday" />');
                    fetchXml.push('<condition attribute="createdon" operator="today" />');
                    fetchXml.push('</filter>');
                    fetchXml.push('</entity>');
                    fetchXml.push('</fetch>');
                }
                //Setting the fetch xml to the sub grid.
                grid.control.SetParameter("fetchXml", fetchXml.join(''));
                //This statement will refresh the sub grid after making all modifications.
                grid.control.refresh();
            }
    	}


  • Mohammed Waseem Profile Picture
    382 on at

    Hi Akhtar ,

    i am always getting null in this case

    var grid = parent.document.getElementById('

    var grid = parent.document.getElementById('OpportunityCurrentFiscalYear');

    ');

    i have my js on load .

    Kindly advise .

    Thanks .

  • Suggested answer
    Community Member Profile Picture
    on at

    Use setTimeout (developer.mozilla.org/.../setTimeout), because grid is not loading immediately, so you need to wait a little.  

  • Community Member Profile Picture
    on at

    try this: document.getElementById('OpportunityCurrentFiscalYear');

  • Mohammed Waseem Profile Picture
    382 on at

    hi ,

    the grid is not refreshinng  .

    below is my code :

    function FundedSupportsSubGrid(){

    var grid = getElementById('OpportunityCurrentFiscalYear');

           //var clientContact = common.getValue('rsa_client_contact');

           if (grid == null ) {

               setTimeout('FundedSupportsSubGrid();', 500);

           } else {

               var fetchXml = [];

                   fetchXml.push('<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">');

    fetchXml.push('<entity name="bis_projectbusinessunit">');

    fetchXml.push('<attribute name="bis_name"/>');

    fetchXml.push('<attribute name="bis_project"/>');

    fetchXml.push('<attribute name="bis_keyaccount"/>');

    fetchXml.push('<attribute name="bis_estrevenue_base"/>');

    fetchXml.push('<attribute name="bis_estrevenue"/>');

    fetchXml.push('<attribute name="bis_estawarddate"/>');

    fetchXml.push('<attribute name="bis_businessunit"/>');

    fetchXml.push('<attribute name="bis_projectbusinessunitid"/>');

    fetchXml.push('<order attribute="bis_name" descending="false"/>');

    fetchXml.push('<filter type="and">');

    fetchXml.push('<filter type="or">');

    fetchXml.push('<condition attribute="bis_competitor" operator="eq" uitype="competitor" value="'+ Xrm.Page.data.entity.getId()+'"/>');

    fetchXml.push('<condition attribute="bis_competitor2" operator="eq"  uitype="competitor" value="'+ Xrm.Page.data.entity.getId()+'"/>');

    fetchXml.push('<condition attribute="bis_competitor3" operator="eq"  uitype="competitor" value="'+ Xrm.Page.data.entity.getId()+'"/>');

    //fetchXml += "<condition attribute='bis_competitor' operator='eq' uiname='Alaska' uitype='competitor' value='{A576591D-EDEB-E411-80F3-C4346BACBF08}' />"

    fetchXml.push('</filter>');

    fetchXml.push('</filter>');

    fetchXml.push('</entity>');

    fetchXml.push('</fetch>');

               //Setting the fetch xml to the sub grid.

               grid.control.SetParameter("fetchXml", fetchXml.join(''));

               //This statement will refresh the sub grid after making all modifications.

               grid.control.refresh();

           }

    }

  • Community Member Profile Picture
    on at

    change this line to

    var grid = getElementById('OpportunityCurrentFiscalYear');

    to

    var grid = parent.document.getElementById('OpportunityCurrentFiscalYear');

    or

    var grid = document.getElementById('OpportunityCurrentFiscalYear');

  • Mohammed Waseem Profile Picture
    382 on at

    Hi Saad ,

    I tried Both . still the grid is not refreshing .

  • Community Member Profile Picture
    on at

    Use this condition
    if (grid == null || grid.control == null)
    instead of
    if (grid == null )

    and increase your timeout to 2000

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Hi,

    This is not supported customization, you should not do this. Please share with us your business requirement maybe we would be able to lead you to supported solution.

  • Mohammed Waseem Profile Picture
    382 on at

    Hi Pawel  ,

    As you could see from my fetch Xml which am trying to bind to OOB grid  .

    The Entity Project business Unit has three lookups of competitor named "competitor 1" ,"competitor 2" and "competitor 3" .as we know its not possible by OOB feature to show records of "Project business Unit" where any of the competitor is selected in any of the lookups on "Project business Unit" . so am getting results from fetch xml and binding to a grid on competitor .

    Thanks ,

    Waseem .

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
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans