Search code examples
javascriptvalidationcrmmicrosoft-dynamicsxrm

Validate field/attribute in CRM Dynamics forms using js


I have a problem in validating attribute on a form in CRM dynamics. I added a JavaScript code that validate the attribute value based on my business rules. and added to 2 events, form on save and field on change,

the question is:

1- Is this the best way to validate on attribute?

2- In case of using this way, how can i stop saving the form or passing it as valid ?


Solution

  • I believe that's a good way to validate input. In case you want to stop save in case one of validations fails do following:

    1. Check "Pass execution context" during registration of save event handler.
    2. Add parameter to function that's called during save procedure.
    3. In case your validation fails call following code:

      execObj.getEventArgs().preventDefault()

    You can find more details here -https://msdn.microsoft.com/en-us/library/gg509060.aspx