Hi,
As my name suggests, I am very new to CRM so please bear with me if my terminology is wrong.
I am attempting to utilise the webservices provided by the CRM 2011 SDK to write some data to entities. At the moment, I am merely testing the capabilities, but there are various things I find perplexing.
One is the fact that 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 can see via this link that this seems to be how it is supposed to work, however, I can't understand why this would be.
I thought that the idea behind the SDK was that it was a consistent mechanism of accessing Entity data and therefore any "constraints" provided on the entity would then be enforced no matter what the mechanism of access (ie. SDK webservice, data import, workflow etc).
The reason I wanted to test this was in my quest to work out the best way of enforcing transactional behaviour for CRM access via the webservices. I came across a post indicating that the use of the Entity.RelatedEntities property would help with this. I assumed by creating a "Buiness Required" field and then not providing data would be a good test, but it let the data through. In addition to that, I was using late bound methods of access in the form of;
Entity newEntity = new Entity("my_entity");
newEntity.Attributes["my_field1"] = "ShouldFail2";
newEntity.Attributes["my_name"] = "ShouldFail2";
Entity child = new Entity("my_child");
child.Attributes["my_name_that_does_not_exist"] = "Child name2"; // this attribute actually doesn't exist as a field against the CRM entity.
child.Attributes["my_requiredfield"] = "Child Required Field2";
newEntity.RelatedEntities.Add(new Relationship("my_entity_child"),
new EntityCollection
{
EntityName = "my_child",
Entities = { child }
});
service.Create(newEntity);
The code above worked fine, even though the attribute I set didn't exist on the entity. Further to that, the field that was defined as the primary field on my Child entity was left blank. I've tried similar things with early bound entities in the hope that there might be some additional properties showing if an entity field was required or not (it certainly limits the fields I can set as they are all properties of my entity). I haven't managed to find anything as of yet.
Given all that, my questions are;
- Can anyone explain why this would have been designed this way ? (Is there a good reason why the constraint on the required field should only be applicable when using a CRM form)
- Is this behaviour documented anywhere (both the required field and the ability to ignore the primary field and also the ability to assign a value to a attribute that doesn't exist and have the entity save without any error)? I'd be keen to find out any other oddities from the outset.
Any help you can provide in my understanding as to why CRM allows this is much appreciated.
Thanks,
Chris