locked
Is there any way to force the one\parent form to update after saving a many/child record in a quick create form? RRS feed

  • Question

  • I have a sub grid on a form for a one to many entity relationship.

    The quick create form is used to add new many\child record to the sub grid.

    When saving a many\child record a work flow updates the one\parent record.

    The issue I have is that the one\parent form is not refreshed and is therefore displaying old data.

    Is there any way to force the one\parent form to update after saving a many/child record in a quick create form?

    I hope the above makes sense and thanks in advanced

    Dean

    Wednesday, November 4, 2015 1:55 AM

All replies

  • Hi Dean,

        Have you tried using Javascript to refresh the form page? I have not tried this myself with a Quick Create form, but it might work. The trick would be getting it to fire on the right event (save?) and then having the javascript refresh the parent form (not the quick create child form).

    John

    Wednesday, November 4, 2015 3:24 AM
  • Thanks for your response. 

    Is there a way of doing this using supported JavaScript?

    I have seen the suggested solution, it involves using JavaScript similar to the below code (copied from http://www.crmanswers.net/2013/07/bind-function-to-subgrid-refresh.html).

    This code seems to be exactly what I need except there is a requirement to not use any unsupported JavaScript. My understanding is the line var gird = document.getElementById(gridName) is unsupported.

    function AddEventToGridRefresh(gridName, functionToCall) {
       // retrieve the subgrid
       var grid = document.getElementById(gridName);
       // if the subgrid still not available we try again after 1 second
       if (grid == null) {
           setTimeout(function () {AddEventToGridRefresh(gridName, functionToCall);}, 1000);
           return;
       }
       // add the function to the onRefresh event
       grid.control.add_onRefresh(functionToCall);
    }

    Thursday, November 5, 2015 1:45 AM
  • Hi Dean,

       Try Xrm.Page.GetControl. If you know the subgrid control name, try replacing the getElementById javascript function with this.

    https://msdn.microsoft.com/en-us/library/dn932126.aspx

    Hope that helps!

    John

    Thursday, November 5, 2015 2:10 AM
  • Ok I have made progress. Below is the JavaScript code I am using and it works.

    The problem is the RefreshPage method is called multiple times after saving the quick create form. I know the refreshPage method is called multiple times because I get a number of alerts.

    Why is this?  

    function propertyOnLoad() {
        addEventToGridRefresh("Roofs", refreshPage);
    }
    
    function addEventToGridRefresh(gridName, functionToCall) {
        alert('test2');
    
        // retrieve the subgrid
        var grid = Xrm.Page.getControl(gridName);
        // if the subgrid still not available we try again after 1 second
        if (grid == null) {
            setTimeout(function () { Property.addEventToGridRefresh(gridName, functionToCall); }, 1000);
            return;
        }
            
        // add the function to the onRefresh event
        grid.addOnLoad(functionToCall);
            
    }
    
    function refreshPage() {
        alert('test');
        debugger;
        Xrm.Page.data.refresh();        
    }


    Thursday, November 5, 2015 7:11 AM