2

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 ?

Hussein Fawzy
  • 525
  • 1
  • 8
  • 15

1 Answers1

4

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

Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13
  • Thank you for this information, but the problem in this solution that it redirect to the cases page with simple error message , is there another way to control this message – Hussein Fawzy Aug 17 '15 at 09:17
  • What Andrii has mentioned should work for your requirement. Can you please elaborate on what exactly is required? – Renjith Aug 17 '15 at 09:30
  • What exactly required is to make this validation looks like the OOB validations that makes red 'X' beside the field and so on. – Hussein Fawzy Aug 28 '15 at 12:14
  • You can add notification to a field - https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_setnotification and put focus on it. – Andrew Butenko Aug 28 '15 at 15:38