How to stop Quick Create form from saving – XrmMtl Skip to content

How to stop Quick Create form from saving

I ran into this problem today. I wanted to use the Quick Create form and do some custom validations in JavaScript. I could of done it by Plugin but I wanted the JavaScript look & feel.

Naturally, I tried context.getEventArgs().preventDefault(). Without success. The save did stop but the save button was disabled (to prevent another save on the stack, probably) and the loading dot were still shown above the form. It seems the function was not adapted to run into a Quick Create context.

I looked up on the Web and found a post on the CRM forum describing the problem and found a partial solution. So here’s the full solution. #unsupported

onSave: function (context) {

  if (!validateStuff()) { 
    context.getEventArgs().preventDefault(); 
    setTimeout(function () { 
      top.document.getElementById('globalquickcreate_save_button_NavBarGloablQuickCreate').disabled = false;
      top.document.getElementById('globalquickcreate_loading_bar_NavBarGloablQuickCreate').style.visibility = 'hidden';
    , 0);
  }
}

Basically, I do my validation then use the supported method. Then, I fix the save button and the loading dots. Also, I wrap everything in a setTimeout to delay the execution. Otherwise, the code is done before CRM’s.

In my professional opinion, the fact it’s unsupported doesn’t bother me because we are still using the supported way. Then, we are just adding a fix. If it does bother, add a try catch inside the SetTimeout. You are garanteed bullet-proof code that won’t ever crash.

Published inJavascriptUnsupported