Announcements
I cant find OnDelete/Change-Events in Dynamics CRM subgrids.
In the related subgrid, the user will delete record. After this, there is a plugin for updating the parent lead entity. I want to refresh the parent form after successful update. Is it possible?
CRM-Version: Microsoft Dynamics 365 (8.2.2)
Thanks
*This post is locked for comments
There are four events of grid:
OnChange
OnLoad
OnRecordSelect
OnSave
Hope it clears your doubt.
Was looking for this exact functionality for our Dynamics 365 v9.x on premise environment. Thank you "Wei Jie Fun", this worked perfectly!
Hi,
the below is my code
//copy from here
var totalrecordonload;
function onLoad()
{
try {
//setting timeout beacuse subgid take some time to load after the form is loaded
setTimeout(function () {
//validating to check if the sub grid is present on the form
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Contacts") != null && Xrm.Page.getControl("Contacts") != undefined) {
//stores the row count of subgrid on load event of CRM Form
totalrecordonload = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();
//registering refreshform function onload event of subgrid
Xrm.Page.getControl("Contacts").addOnLoad(SetSubgridOnLoad);
}
}, 5000);
} catch (e)
{
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
function SetSubgridOnLoad()
{
try {
//setting timeout beacuse subgid take some time to load after the form is loaded
setTimeout(function () {
//validating to check if the sub grid is present on the form
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("Contacts") != null && Xrm.Page.getControl("Contacts") != undefined) {
//stores the row count of subgrid on load event of CRM Form
var aftertotal = Xrm.Page.getControl("Contacts").getGrid().getTotalRecordCount();
if (totalrecordonload != aftertotal )
{
alert("Total Record Onload " + totalrecordonload + " after deleted " + aftertotal);
totalrecordonload = aftertotal ;
Xrm.Page.data.refresh(false);
}
else
{
}
}
}, 5000);
} catch (e)
{
Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
}
}
//copy until here
you can take a look on below video, how it works in my environment.
ok, but this is a refresh of the subgrid, I want to refresh the parent form after create/delete subgrid elements
Thanks, good idea but the
Hi,
during onload of the form , go get the total records of that subgrid and store into a global variable.
after record get deleted, get the total records of that subgrid again and compare to the global variable , if the result is not same only refresh.
Hi ,
Please try with this . Hope this helps.
function Onload() { var intervalId = window.setInterval( function () { if (Xrm.Page.ui.controls.get("subgridname") != null) { window.clearInterval(intervalId); var subgrid = Xrm.Page.ui.controls.get("subgridname"); subgrid.refresh(); } }, 500); }
Thanks,
I try this
onLoad() {
var contactsSubgrid = Xrm.Page.getControl("Contact");
var myContactsGridOnloadFunction = function ()
{
Xrm.Page.data.refresh(false);
};
contactsSubgrid.addOnLoad(myContactsGridOnloadFunction);
}
...
but this will cause an endless loop
Hi,
after deleted the record, the gridview will refresh automatically , so use below method to register your function via addonload
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156