Search code examples
javascriptdynamics-crmcrmdynamics-crm-onlinewebresource

Pass data from html webresource window in MS Dynamics CRM


I need to pass data (an array of strings) from html webresource window to the form. Please note, window means window (it is NOT embedded in CRM form, is NOT a dialog, it is a window opened from the form). I used Xrm.Utility.openWebResource. I need either to influence fields on the form or call a js function on the form. Any help is appreciated.

P.S. "onunload" is ignored by Chrome


Solution

  • Try something like this. Invoking a function from child in parent by window.opener is feasible. Also you need Json library to serialize/deserialize so that objects can be sent between windows.

    In CRM parent window:

    function openWebResource() {   
        var popupWindow = Xrm.Utility.openWebResource(...);
    }
    
    function callFunction(myObjects) {
        var entity = JSON.parse(myObjects);
    
        if (entity) {
               var value = new Array();
               value[0] = new Object();
               value[0].id = entity.Id;
               value[0].Name = entity.Name;
    
           // do your logic here
        }
    }
    

    In popup window (web resource):

    function callParent() {
        var entity = {};
        entity.Id = 1;
        entity.Name = “test”;
    
        var arr = JSON.stringify(entity);
        window.opener.callFunction(arr);
    }