Nick
Nick

Reputation: 850

Revert Dynamics CRM Form Changes (by user) Using JavaScript

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.

Upvotes: 2

Views: 3345

Answers (3)

keerz
keerz

Reputation: 717

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

Upvotes: 0

Daryl
Daryl

Reputation: 18895

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.

Upvotes: 0

djluis
djluis

Reputation: 362

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

Upvotes: 3

Related Questions