在CRM2011表单中取消OnSave操作

好像SDK里没有记这东西,在国外的一博客里找了个贴过来备忘。

 

转自:http://blogs.infinite-x.net/2011/05/06/crm-2011-canceling-the-save-operation/

 

---------------------------------

There are occasions where you need to abort the saving of a record within CRM. This is accomplished by using JavaScript to instruct CRM to prevent the default action ( which is a save operation ).

This requires a small piece of JavaScript in the OnSave Event which we will do in the following steps:

Adding a web resource for the contact form

In order to utilize JavaScript on our form, we must first attach a JavaScript library web resource to the form:

Next, we must add an OnSave event to the form:

 

Note: The pass execution context as first parameter checkbox is very important to this process. Without it, it will not work.

Inside the Contact_main_library.js web resource, we’ll add the following function:

function Form_onsave(executionObj)
{
    var shouldSave = true;

    if (shouldSave)
    {
        alert("Unable to save because of some reason or the other.");

        executionObj.getEventArgs().preventDefault();
    }
}

Inside the OnSave function, we need to have some type of test to see if we should allow the record to be saved.

For this demonstration, we simply check the value of a variable called shouldSave. If true, then we display an error message to the user then execute the preventDefault() method which will instruct CRM to cancel the save operation.

Note: in an actually CRM system you would probably perform checks such as validating data entered by the user is correct and/or appropriate.

It should also be noted that if you have required fields on the form, CRM will validate those fields first. If any required fields are blank, an warning message will be displayed to the user so they may complete those fields.

The OnSave event is only fired after all required fields have been populated.

转载于:https://www.cnblogs.com/bcszz/archive/2012/05/26/2519593.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值