EnforceConstraints
It's really nice to see people try using the techniques I'm posting here. But, as usual, there are glitches when this stuff comes in contact with the real world. Here's a really relevant comment from a user:
"When I try to insert a new DataRow to the first table of the Dataset (my Groove form) I got an error since it says that the RecordURI is required. I'm confused since I don't want to insert the RecordURI, the CreatedURL the modifiedURL etc..."
In my code to create a DataSet from the RecordDataSet structure which is used by the GrooveForms2 service, there's a line which this user had missed out. It says:
recordDataSet.EnforceConstraints = false;
Turns out, if you relax the DataSet's constraints, you can insert records just fine. To understand why, let's look at the XML version of the schema for a very simple form with only one text field:
<xs:complexType>
<xs:sequence>
<xs:element name=\"MyFormsField\" type=\"xs:string\" minOccurs=\"0\" />
<xs:element name=\"RecordURI\" type=\"xs:string\" />
<xs:element name=\"_ParentID\" type=\"xs:double\" />
<xs:element name=\"_RecordID\" type=\"xs:double\" />
<xs:element name=\"_Created\" type=\"xs:dateTime\" />
<xs:element name=\"_CreatedBy\" type=\"xs:string\" />
<xs:element name=\"_CreatedByURL\" type=\"xs:string\" />
<xs:element name=\"_Modified\" type=\"xs:dateTime\" />
<xs:element name=\"_ModifiedBy\" type=\"xs:string\" />
<xs:element name=\"_ModifiedByURL\" type=\"xs:string\" />
<xs:element name=\"Forms_Tool_grooveFormID\" type=\"xs:double\" />
<xs:element name=\"_Editors\" type=\"xs:string\" />
<xs:element name=\"_Readers\" type=\"xs:string\" />
<xs:element name=\"_UnreadFlag\" type=\"xs:double\" />
</xs:sequence>
</xs:complexType>
The user-defined field says minOccurs=0. All the system fields, on the other hand, don't have this; they are "required". So the DataSet constraints prevent you from adding a row which doesn't specify values for the system fields.
To which there are three possible solutions:
- Relax constraints in the DataSet. This is the recommended route.
- Remove all the system columns from the DataSet before you insert rows. This is a really good choice, since it reduces the amount of data sent in the SOAP packet when you insert or update records in the tool. But it's slightly more work than just relaxing constraints.
- Set arbitrary values in these fields. Don't do this.
The bottom line: use EnforceConstraints=false. It's safe and easy.