Refresh ISV/WebResource after CRM 2013/2015/2016 Save Event

I had a Web Resource page which needed to refresh a jqgrid on it after some fields on a CRM form were updated and record was saved. In order to do this a ran a watcher to check to see if the modified date of the record had changed if so I ran the code to update the grid. This code is on the actual Web Resource page not the form JS. Also a quick note you may want to run another watcher to make sure window.parent.Xrm.Page is not null before you run this code.
//set the initial modified on date
var prevModifedOn = window.parent.Xrm.Page.getAttribute('modifiedon').getValue();

var xrmPageWatcher = window.setInterval(function () {
    //check to see if the date is modified, convert to string since JS doesn't know how to convert the CRM date time to a datetime object
    if (window.parent.Xrm.Page.getAttribute('modifiedon').getValue().toString() != prevModifedOn.toString()) {
    //update the previous data time so we can detect another save
    prevModifedOn = window.parent.Xrm.Page.getAttribute('modifiedon').getValue();
    //refresh our JQ grid or do whatever else you want like refresh the whole web resource etc.
    $("#grid").jqGrid('setGridParam', { data: awardsDS.generateDataTable(true) }).trigger('reloadGrid');           
    }            
}, 500);   

Comments

  1. Honestly, I'm very bad at system code, but the idea is pretty good. But when I had to solve such problems, I just prefer to ask for help from professionals, like this guys https://www.bitrix24.com/uses/free-hosted-CRM.php. I never regretted the choice of their company and software.

    ReplyDelete

Post a Comment

Popular posts from this blog

Add User As Local Administrator On Domain Controller

Calling Dataverse Web API in PowerShell using Client Credentials

Windows Server 2008R2 VMs Shut Down After 1 to 2 Hours