Wednesday, 11 December 2019

How to disable Auto-Save in Dynamics 365 for Specfic form

How to disable auto-save for a form

If you wish to disable auto-save for specific entity forms, you can do this by adding code to the OnSave event in the entity form.
1. Create a JavaScript web resource and add it to the form
  • Enter the following information in the web resource form:
    • Name: preventAutoSave
    • Display Name: Prevent Auto Save
    • Type: Script (JScript)
  • Next to the Type field, choose Text Editor.
  • In the Source field, paste the following code (see code box below to copy):
auto-save
function preventAutoSave(econtext) {
    var eventArgs = econtext.getEventArgs();
    if (eventArgs.getSaveMode() == 70 || 
eventArgs.getSaveMode() == 2) {
        eventArgs.preventDefault();
    }
}
  • Add the web resource to the Form
2. Configure the OnSave event
  • In the Form Properties window, in the Event Handlers section, set Event to OnSave.
  • Enter the following in the Handler Properties:
    • Type ‘preventAutoSave’ in the Function field. This is case sensitive. Do not include quotation marks.
    • Make sure that Enabled is checked.
    • Check Pass execution context as first parameter.
  • If there are any other event handlers for the OnSave event, use the green arrows to move this one to the top
Auto-save will now be disabled for the form, but data can still be saved by clicking the Auto save button in the lower-right corner. If users attempt to navigate away from a form or close a form where data has been changed, they will get a prompt to save their changes before they can navigate away or close the form.

No comments:

Post a Comment

How to use Form Component Control to Edit Related Entity Information in Dynamics 365 CRM

In the recent release of the Dynamics 365 CRM, new features have been added. One of the most important and useful features among these is th...