在Javascript里,我们取消一个事件可以用 window.event.returnValue来解决。
比如点击一个链接 <a .... /> ,我们可以为这个链接增加一个 onclick 的事件处理,并在处理中加上 window.event.returnValue = false , 这样该链接就不会把我们跳转到另一个制定的 URL 了。
在CRM 4 里,我们也有类似的处理方法。在一个 Form 的 OnSave 处理里,我们可以用 event.returnValue = false, 来取消保存。
在CRM 2011 里,取消 Form 的 OnSave 就要更复杂了。
首先要在添加 OnSave的处理函数时选中 “Pass execution context as first parameter”
然后在你定义的函数中,首先要有一个关于context的ExecutionObj参数,然后可以使用ExecutionObj.getEventArgs().preventDefault()
function OnSaveHandler(ExecutionObj){
//Place all your data validation here
//In case data is not valid call the below method
// The getEventArgs() method returns an object with methods to manage the Save event.
// The preventDefault() method cancels the save operation
ExecutionObj.getEventArgs().preventDefault();
}
具体也可以参见 CRM 2011 SDK "Save Event Arguments Reference" 一节。