Refresh Opportunity subgrid on tab expand

In this article , I am explaining how to we can refresh entity page subgrid and chart control on tap expand. I have created one tab with id “tab_oppty” and as we expand that tab and on tab expand our custom javascript will execute and display results in sub grid and chart according to our filter condition


This script need to execute on tab state change event in ms crm dynamics 2011

var resetGrid = function (grid, chart) {
    var p = document.getElementById(grid);
    if (p.readyState != "complete") {
        setTimeout('resetGrid("' + grid + '","' + chart + '")', 100); 
        return;
    }

    var state = Xrm.Page.ui.tabs.get('tab_oppty').getDisplayState();
    if (state == 'expanded') {
        var accountid = Xrm.Page.data.entity.getId();
        //document.getElementById(grid + '_filterSet').control.RefreshWithFilters();

        //filter condition (it will change according to your requirement here i am using normal conditions for this article)
        var linkfetchxml = '<filter type = "or">';
        linkfetchxml += '<condition attribute="statecode" ';
        linkfetchxml += 'operator="eq" value="0" />';
        linkfetchxml += '<condition attribute="statecode" ';
        linkfetchxml += 'operator="eq" value="1" />';
        linkfetchxml += '<condition attribute="statecode" ';
        linkfetchxml += 'operator="eq" value="2" />';
        linkfetchxml += '</filter>';

        var c = document.getElementById(chart).control;
        var q = "<fetch version='1.0' output-format='xml-platform' mapping='logical'>" +
	        "<entity name='opportunity'>{0}" +
		    "<order attribute='name' descending='false' />" +
		    "<link-entity alias='a_f9e0863b877f4fddbf58c23a2b952c10' name='account' from='accountid' to='customerid' link-type='inner' visible='false'>" +
            "<filter type = 'and'>" +
            "<condition attribute='accountid' operator='eq' value='" + accountid + "' />" +
            "</filter>" +
			"<attribute name='emailaddress1' />" +
		    "</link-entity>" +
		    "<attribute name='createdon' />" +
		    "<attribute name='estimatedclosedate' />" +
		    "<attribute name='estimatedvalue' />" +
		    "<attribute name='new_opportunitytypeid' />" +
		    "<attribute name='customerid' />" +
		    "<attribute name='closeprobability' />" +
		    "<attribute name='opportunityratingcode' />" +
		    "<attribute name='new_teamid' />" +
		    "<attribute name='name' />" +
		    "<attribute name='new_primarycontactid' />" +
		    "<attribute name='opportunityid' />" +
	        "</entity>" +
            "</fetch>";
        q = q.replace('{0}', linkfetchxml);
        c.setParameter("fetchXml", q);
        document.getElementById(chart).control.refresh();

        var g = document.getElementById(grid).control;
        var b = "<fetch version='1.0' output-format='xml-platform' mapping='logical'>" +
	        "<entity name='opportunity'>{0}" +
		    "<order attribute='name' descending='false' />" +
		    "<link-entity alias='a_f9e0863b877f4fddbf58c23a2b952c10' name='account' from='accountid' to='customerid' link-type='inner' visible='false'>" +
            "<filter type = 'and'>" +
            "<condition attribute='accountid' operator='eq' value='" + accountid + "' />" +
            "</filter>" +
			"<attribute name='emailaddress1' />" +
		    "</link-entity>" +
		    "<attribute name='createdon' />" +
		    "<attribute name='estimatedclosedate' />" +
		    "<attribute name='estimatedvalue' />" +
		    "<attribute name='new_opportunitytypeid' />" +
		    "<attribute name='customerid' />" +
		    "<attribute name='closeprobability' />" +
		    "<attribute name='opportunityratingcode' />" +
		    "<attribute name='new_teamid' />" +
		    "<attribute name='name' />" +
		    "<attribute name='new_primarycontactid' />" +
		    "<attribute name='opportunityid' />" +
	        "</entity>" +
            "</fetch>";
        b = b.replace('{0}', linkfetchxml);
        g.setParameter("fetchXml", b);
        document.getElementById(grid).control.refresh();

    }

};    

This entry was posted in MS Dynamic CRM 2011. Bookmark the permalink.

8 Responses to Refresh Opportunity subgrid on tab expand

  1. Steven says:

    Much appreciated for the information and share!

  2. The recommendations you contributed here are rather useful. It turned out such a fun surprise to get that looking forward to me when I woke up this very day. They are usually to the point and simple to grasp. Thank you so much for the valuable ideas you’ve got shared right here.

  3. aging says:

    What would we all do devoid of the brilliant ideas you write about on this site? Who has the persistence to deal with critical topics for the health of common readers like me? My spouse and i and my guys are very lucky to have your web blog among the ones we frequently visit. We hope you know how very much we get pleasure from your working hard! Best wishes through us all.

  4. It was my pleasure discovering your site a short while ago. I arrived here now hoping to uncover something new. And I was not disappointed. Your ideas upon new solutions on this subject matter were insightful and a good help to us. Thank you for making time to write down these things and then for sharing your thoughts.

  5. The points you provided here are quite valuable. It had been such a fun surprise to see that waiting for me as i woke up this very day. They are always to the point and easy to understand. Thank you so much for the useful ideas you’ve shared right here.

  6. It was a real excitement coming across your site this morning. I got here right now hoping to find out interesting things. I was not dissatisfied. Your ideas for new methods on this subject matter were topical and a wonderful help to me and my spouse. Thank you for having time to create these things and for sharing your ideas.

  7. We really appreciate your website post. There are actually so many tactics we could put it to really good use while having no effort in time and resources. Thank you very much for helping have the post reply many concerns we have experienced before now.

  8. It is rare to locate a professional person in whom you may have some confidence. In the world these days, nobody absolutely cares about showing others exactly how in this subjecttopic. How happy I am to have actually found a really wonderful blog as this. It really is people like you who make a genuine difference nowadays through the tips they talk about.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>