Please wait, loading...

 

Refresh SubGrid – Not Working – Issue while refreshing Sub grid using JavaScript -Refresh SubGrid from HTML webresource

July 8, 2020

With Recent Requirement, we developed a Custom Multiple File uploader on an entity which uploads multiple files in Notes or Attachment (Unsupported for sure),

Once the upload is done we needed Notes Grid or Attachment subgrid to refresh, but as we were running js from HTML Resource, so we followed below code

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/07/img_5f05ec766f06a.png?fit=1497%2C746&ssl=1

There are 2 ways we can use it.

1. Using it from Html Resource where we want to use DOM. ( Unsupported not recommended)

parent.document.getElementById("attachmentsGrid").control.refresh();

2. Using Js from an Iframe, use Parent

parent.Xrm.Page.getControl("attachmentsGrid").refresh();

// Form Context (Recommended)

formContext.getControl(“attachmentsGrid”).refresh();

3. Using Js on the Record Itself

Xrm.Page.getControl("attachmentsGrid").refresh();

// Form Context (Recommended)

formContext.getControl("attachmentsGrid").refresh();
We Might be sometime not Seeing above code working, I would recommend debugging it, but the most common issue might be that Code is rendering Before Form is fully loaded.

We can use the below code, to the first check if the context is not null and if null is found return and try after 1 sec that is 1000ms.

Function test(executionContext)
{
//// Get FormContext
formContext = executionContext.getFormContext();
if(formContext  != null)
{
//// Get Grid Control
Var getSubgrid = formContext.getControl("attachmentsGrid");
////If Grid Control is empty , Return and timeout for 1 sec
if(getSubgrid  == null)
{
 setTimeout(function () { test(executionContext); }, 1000);
     return;
}
//// If control is not null refresh the grid
formContext.getControl("attachmentsGrid").refresh();
}

}
https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651&ssl=1
Microsoft Dynamics Community Profile

Learn more