0

In MS Dynamics CRM 2011 when a field on an entity is marked as "Business Required", I can create an entity via the webservice SDK without having to provide a value. I've read that this is widely known (and for some reason acceptable), yet I can't see it in any MS documentation. Apparently, business required fields will also accept null values for access via plugins, data imports and workflows.

  • What is the reason behind this? Any reference to MS documentation would be appreciated.

  • If your answer is to the first question is to allow flexibility, then why are other constraints such as field length constraints on "Single Line of Text" adhered to when the Business Required constraint isn't?

Mr Moose
  • 5,946
  • 7
  • 34
  • 69

1 Answers1

4

A 'requried' field is a concept that only applies on the clientside (e.g. on the form). As you are creating the entity via the SDK (or plugin, or workflow) the clientside scripts are not invoked and so the required status of the field is not checked.

So it isn't flexibility as much as it is not possible to do.

Other constraints, such as field length, as concepts enforced at the DB level. Hence these will be invoked via SDK, plugin etc.

If you wanted to enforce the required fields it is fairly straightforward - add a pre create plugin. Check for values in desired values. If not found, throw an exception.

glosrob
  • 6,631
  • 4
  • 43
  • 73
  • I see what you are saying, but I'd rather have the check for values tied to the entity definition rather than hardcoded rules around what is required. The only way to do this is by querying the metadata and that would be slow in a plugin. – Mr Moose Mar 14 '13 at 09:04
  • I agree it isn't ideal (and would be a pain maintain) - I guess that is why MS don't do it out of the box (speed issues) – glosrob Mar 14 '13 at 09:05
  • Also, I've heard that field length constraints are only partially enforced by the DB. I'm yet to verify this myself, but I've heard that increasing the characters required will force a change to the DB column type, but reducing it won't. therefore, I'm assuming there must be some checking within CRM itself. – Mr Moose Mar 14 '13 at 09:07
  • That is interesting - hadn't heard that. If the field length is reduced it might be that in order to protect existing data they don't update the DB (if they did data would be truncated). Also it is going to be enforced at the DB level anyway, so better for MS to check at service level and give a friendlier error. – glosrob Mar 14 '13 at 09:16
  • Just as a side point, CRM enforces the required fields on some entities for some fields, e.g. incident & customerid. But those are 'special' and I don't believe we can do that. – James Wood Mar 14 '13 at 09:32
  • 1
    For clarity, glosrob says "eg on the form". Actually, Forms are the ONLY place that "Business Required" has any real impact. Workflows can ignore them (when running, not when editing as that uses a form), data import can ignore them (despite nagging the user it will just work), and of course javascript on a form can change the requirement level to make things interdependent rather than "hard" dependencies in the database ("If you choose option 1 for field A, then B is required, else C is required") – AdamV Mar 14 '13 at 09:38
  • I think you're right about existing data being the reason as to why it isn't reduced. Allowing the user to make these changes without affecting existing data is probably why the underlying column isn't made nullable too. Like I say, I'd just expect that ALL constraints should be enforced in the service level. – Mr Moose Mar 14 '13 at 09:45