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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Subgrid.addonload() not working

(0) ShareShare
ReportReport
Posted on by

Hi, I am using below code to bind a function onload to the subgrid. If I remove line grid.addOnload I can see entire subgrid on the form and if I keep the line I can only see the header of the subgrid.

function AddEventToGridRefresh(gridName, functionToCall) {
var grid = Xrm.Page.getControl(gridName);
// if the subgrid still not available we try again after 1 second
if (grid == null) {
setTimeout(function () { AddEventToGridRefresh(gridName, functionToCall); }, 5000);
return;
}
// add the function to the onRefresh event
grid.addOnLoad(functionToCall);
}

1258.subgrid1.PNG4338.sub2.PNG

The system I am using is Microsoft Dynamics 365 Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises. 

*This post is locked for comments

I have the same question (0)
  • Clem Profile Picture
    2,541 on at

    Hi,

    It seems that you created an other post for the same issue : community.dynamics.com/.../263489

    I see that in the functionToCall you call one named : "setSubgridVisible".

    If you comment out that part, do  you still have the issue ?

    Just tried to reproduce your error with my onprem env and based on the code you posted and my functionToCall just display a javascript alert, everything works fine.

    Clément

  • Community Member Profile Picture
    on at

    Hi,

    thanks for your reply. I couldn't delete the other post somehow, so the other post is still there.

    If I comment out setSubgridVisible, issue is not solved.

    Only if I comment out grid.addonload(); line then only everything works perfectly.

  • Clem Profile Picture
    2,541 on at

    Thanks for your answer here.

    What if you replace your current functionToCall by something like :

    function() { alert("onload grid loaded"); }

    Will you still have the issue ?

  • Community Member Profile Picture
    on at

    Sorry for late reply but as I mentioned, only if I remove addonload() function call line, it works fine.

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    would be good if you can share your grid view name via screenshot and the gridname you pass to JS.

    Thanks

  • surucas Profile Picture
    on at

    This worked for me in version 9.0

    function onLoadViewRelationshipOwner(context) {

       debugger;

       var formContext = GetFormContext(context);

       var customertypecode = GetItemValue(formContext, "customertypecode");

       var statecode = GetOptionValue(formContext, "statecode");

       var gridContext = formContext.getControl("OWNER_BY_LOCATION_SUBGRID");

       var ActiveRelationshipOwner = {};

       gridContext.addOnLoad(setView);

       function setView() {

           debugger;

           if (customertypecode == 923760006) {

               // Is Active

               if (statecode != 1) {

                   ActiveRelationshipOwner = {

                       entityType: 1039, // SavedQuery

                       id: "{FAFDDC37-5FE8-459E-B434-CC80227289CA}",

                       name: "Active Relationship Owners"

                   }

                   if (gridContext != null) {

                       // Set the view using ContactsIFollow

                       debugger;

                       gridContext.getViewSelector().setCurrentView(ActiveRelationshipOwner);

                       gridContext.removeOnLoad(setView);

                   }

               }

                   // Is Inactive

               else {

                   ActiveRelationshipOwner = {

                       entityType: 1039, // SavedQuery

                       id: "{6ACD9FA3-EAF6-43A2-8B95-D4345C62E217}",

                       name: "Inactive Relationship Owners"

                   }

                   if (gridContext != null) {

                       // Set the view using ContactsIFollow

                       debugger;

                       gridContext.getViewSelector().setCurrentView(ActiveRelationshipOwner);

                       gridContext.removeOnLoad(setView);

                   }

               }

           }

       }

       try {

           gridContext.refresh();

       } catch (e) {

       }

    }

    I had to create a try, catch to refresh grid

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans