Friday, December 23, 2011

How to stop CRM form from saving

I had to write some validation code on the OnSave event of the form and if the validation code was not successful I needed to cancel the save. To accomplish this you have to use JavaScript and you need to pass context to your javascript function.
If your business logic fails you need to call this function.
ExecutionObj.getEventArgs().preventDefault();
Where ExecutionObj is the first parameter of the function (i.e. context object).

Cheers

2 comments:

  1. little confused.. what should be replaced with ExecutionObj????? plz provide few examples..

    ReplyDelete
    Replies
    1. ExecutionObj is the context object. So when you add your function on the form tick the box that say pass context as the first argument.
      Now that means that the first parameter in your javascript function is the context object and you can cancel your save event from there.

      Delete