1
votes

Just wondering how to revert changes in Dynamics CRM done by a user using Javascript. For example if a user tries to create a new record for Entity A and sets the value of Attribute A on Entity A Form to X and clicks save, I need JavaScript to display a message saying Type X cannot be created by User and prevent the user from saving the Form. Same thing on Update When user try to Set Attribute A to X and click save, JavaScript should display a message and prevent the save to happen and rollback to previous values for all attributes before the user changes.

3

3 Answers

3
votes

You need to call the following method in the OnSave Event.

In the PreventOnSave method make sure you have a parameter defined to receive the Execution Object.

function PreventOnSave(ExecutionObj){
        // The getEventArgs() method returns an object with methods to manage the Save event.
        // The preventDefault() method cancels the save operation
        ExecutionObj.getEventArgs().preventDefault();
    }

Microsoft reference here

0
votes

Rather than catching the errors on the save, I would just disable the field via javascript in the on-load. This way your user won't attempt to update something they can't.

0
votes

As Daryl says, if the user shouldn't be changing a field AT ALL, make the field readonly OnLoad() of form.

As Shanks points out, you also have the ability to catch ALL changes in OnSave() where you can inform the user of ALL disallowed changes for the form and take action

3rd option is to attach a supported OnChange() per field and handle each disallowed field edit as it happens