简体   繁体   中英

CRM 2015 Javascript, prevent record form from SAVE AND CLOSE

I need to develop a custom function using JavaScript for CRM 2015. What I would like to achieve is when a user hits 'Save and Close' button, it prevents record form from saving and close if the validation is not passed.

I googled it and tried eventObj.getEventArgs().preventDefault(); return false; eventObj.getEventArgs().preventDefault(); return false; which most people recommended. It does prevent form from saving, but the form still closed. The reason is that 'preventDefault canceled the save operation, but all remaining handlers for the event will still be executed'.

Is there a way to cancel remaining event handler, and prevent form from both SAVE and CLOSE ?

If you have an web resource file, you can directly add button's command with Ribbon Workbench. Here is a link : http://ribbonworkbench.uservoice.com/knowledgebase/articles/80806-download-ribbon-workbench-for-crm-2011-2013-2015

For doing that, here is the steps :
1. Right click to "save & close" button and click customise command.
2. After that, you must see the created command for button in commands section.
3. Right clik the command and select edit actions.
4. Select add, then select "Javascript Function Action".
5. Select your library and function, and write your parameters if you need.
6. Last step is publishing.

One thing you have to be careful about is you can fire just one function. This can be painful but if have something like this :

function baseFunction(){
  //steps
  anathoerFunction();
}
function anotherFunction(){
  //steps
}

This will not work with ribbon workbench. You have to use it in one function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM