CRM 2013: Force refresh a form after save

Rajesh picture Rajesh · Aug 11, 2014 · Viewed 25.8k times · Source

We have a requirement to refresh the form after saving (to ensure that some hide/show logic works as expected based on a field value).

Currently the form does not automatically refresh after saving the record.

I have gone through some articles and found this reference: http://msdn.microsoft.com/en-us/library/dn481607%28v=crm.6%29.aspx

When I try to do either of the below, it results in an infinite loop and throws a 'Callstack exceeded Max limit' error.

  1. OnSave(context)
    {
      //my logic 
      ...
      ...
    
      Xrm.Page.data.save.then(SuccessOnSave, ErrorOnSave);
    }
    
      function SuccessOnSave()
     {
      //force refresh
       Xrm.Page.data.refresh();
     }
      function ErrorOnSave()
      {
        //do nothing
      }
    
  2.   OnSave(context)
     {
       ...
      ...
      //force refresh
      Xrm.Page.data.refresh(true).then(SuccessOnSave, ErrorOnSave);
    }
    
      function SuccessOnSave()
     {
      //do nothing
     }
      function ErrorOnSave()
      {
        //do nothing
      }
    

Can someone please explain me how to use the refresh or save method to do a force refresh of the form ??

Rajesh

Answer

MaKeer picture MaKeer · Aug 15, 2014

I use to achieve it with following code

 Xrm.Page.data.save().then(
    function () {
        Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
            attribute.setSubmitMode("never");
        });
        Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    },
    function (errorCode, message) {
    }
    );