1
votes

In Dynamics CRM 2016 we have a Quick Create Form which works well. But once the Quick Create is done, and the record is saved (and the new record appears in the sub-grid in the parent form), the roll-up field under the sub-grid doesn't get re-refreshed on the screen until the user presses F5.

(we have some C# code to update the roll-up).

Does anyone know how to force the refresh of the main form after the Quick Create has successfully run?

enter image description here

3
Roll-up fields don't get calculated automaticallyjasonscript
yes, we've got a C# plugin that does it. but the new value still doesn't display until after the F5Rodney Ellis
ok, so the roll-up field is recalculated, just the UI is not updatedjasonscript
sorry yes. i just edited the issue to clarify. i should've written "refreshed" not "re-calculated". sorry, am new to CRMRodney Ellis

3 Answers

2
votes

You may add timeout on refresh event, and after 1-2 sec refresh once more.

function OnFormLoad() //add this function onload form
    {
      var subGrid = window.parent.document.getElementById("id of your subgrid")
      if (subGrid !== null) {
        if (subGrid.control)
          subGrid.control.add_onRefresh(fnOnRefresh)
        else
          setTimeout(OnFormLoad, 500);
      } else {
        setTimeout(OnFormLoad, 500);
      }
    }

function fnOnRefresh() {
      setTimeout(function() {
        Xrm.Page.ui.controls.get("id of your subgrid").refresh();
      }, 2000) //after 2 sec refresh subgrid
    }
0
votes

I would try stopping the OOB save event using the below snippet: Read more

function onSave(context) {

  var saveEvent = context.getEventArgs();
  saveEvent.preventDefault();

//save explicitly here 

//reload the window here

}

And then save the entity in code using:

Xrm.Page.data.entity.save();

And then refresh/reload the browser window. I haven’t tried this but very rough theory :)

0
votes

We got it working ... used what Timur suggested but just changed the last function to:

function fnOnRefresh() {
      setTimeout(function() {
		window.parent.location.reload(true);
      }, 500)
    }	 

Thank you