Wednesday, September 16, 2009

Detect CRM4 Grid's Refresh Event

In my previous blog, I have documented the script to load associated view in an IFrame. Sometime, there might be circumstances that we want to manipulate the data in the grid, which is achievable through the crmGrid object (in the IFrame’s document) by listening to its OnRefresh event. The crmGrid has exposed a few events and a few dozens of methods which we can use depending on the scenario.

The following is the code that I am using in my project to listen to the gird’s OnRefresh event. In my case, I need to make one field as required on the CRM form when certain number of records have been detected for the associated entity.

function DetectGridRecordChange() {

    var myframe = crmForm.all.IFRAME_MyFrameId;

    myframe.onreadystatechange = function() {
        if (myframe.readyState === "complete")
            var frameDoc = myframe.contentWindow.document;

            frameDoc.all['crmGrid'].attachEvent("OnRefresh", function()
                // Do something
                alert("CRM Grid refreshed! ");

No comments:

Post a Comment