Sunday 17 June 2018

prevent record when active/inactive in Dynamic CRM

Stopping Deactivation of Records in Dynamics 365

Description:

In this example we explain that how to prevent record’s when Active/Deactivate in Dynamic CRM using JavaScript. Or how to display confirmation Dialog Box when user Active or Deactivate the form Record in Dynamic CRM using JavaScript. Or how we can apply validation logic to prevent Activate/Deactivate of a record from Form in Dynamic CRM using JavaScript.or prevent record deactivation if child record are active using JavaScript.


So here we demonstrate that how to prevent record or display confirmation dialog when Activate/Deactivate record in Dynamic CRM using JavaScript. Below is the JavaScript code that you have to call on Save method of the Form in Dynamic CRM.
Code:
function onSave(econtext) {
            var eventArgs = econtext.getEventArgs();

            // Capture Deactivation(i.e., SaveMode=5) or Activation(i.e., SaveMode=6)
            if (eventArgs.getSaveMode() == 5 || eventArgs.getSaveMode() == 6) {
                // Your business logic goes here
                Xrm.Utility.alertDialog("Preventing Deactivate or Activate");
                eventArgs.preventDefault();
            }

            // Capture AutoSave event (i.e., SaveMode=70)
            if (eventArgs.getSaveMode() == 70) {
                Xrm.Utility.alertDialog("Preventing Auto Save");
                eventArgs.preventDefault();
            }

            // Capture ‘Save and Close’ event (i.e., SaveMode=2)
            if (eventArgs.getSaveMode() == 2) {
                Xrm.Utility.alertDialog("Preventing ‘Save and Close'");
                eventArgs.preventDefault();
            }
        }



0 comments:

Post a Comment