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
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(); } }