Writing Forms Data
Writing a DataSet into a Groove Forms tool is just about as easy as reading data was. I won't bore you with a complete app (at least, not today... next week I'll be carrying around an example which reads from WSS and writes to Groove), but below the essential code fragment.
Assuming we have a DataSet with one table (note: the table name is important), and that the table has some rows whose fields match the fields in our Groove form,
DataSet
ds = new DataSet();
DataTable dt = ds.Tables.Add("FormsRecordData");
then
GrooveFormsWebService.
FormsRecordDataSet formsData = new GrooveFormsWebService.FormsRecordDataSet();
// Translate the schema:
xmlDoc.LoadXml(ds.GetXmlSchema());
formsData.Schema =
new System.Xml.XmlNode[] { xmlDoc.DocumentElement };
// Translate the data:
xmlDoc.LoadXml(ds.GetXml());
if (xmlDoc.DocumentElement.HasChildNodes)
{
int dataNodesLength = xmlDoc.DocumentElement.ChildNodes.Count;
System.Xml.
XmlNode[] dataNodes = new System.Xml.XmlNode[dataNodesLength];
for (int i = 0; i < dataNodesLength; i++)
{
dataNodes[i] = xmlDoc.DocumentElement.ChildNodes[i];
}
formsData.Data = dataNodes;
}
else
{
formsData.Data =
new object();
}
// Send to Groove
string toolURI = tool.Data;
GrooveForms formsService = new GrooveForms();
formsService.GrooveRequestHeaderValue =
new GrooveFormsWebService.GrooveRequestHeader();
formsService.GrooveRequestHeaderValue.GrooveRequestKey =
GWSUtil.GrooveLocalRequestKey;
formsService.GrooveRequestHeaderValue.GrooveIdentityURL = selectedIdentity.URI;
formsService.Url =
GWSUtil.GrooveURL + toolURI;
string[] URIList = formsService.CreateRecords(formsData);
So, like the "reading" example, we translate the schema and the data between the DataSet and a FormsRecordDataSet. This translation is just a matter of passing XML from one to the other, because the Forms data format is just the same as the DataSet's serialization.
Updating a set of records, using the UpdateRecords() call, is very similar to CreateRecords(); each record must be identified already with its record URI. Updates don't require you to set values in any fields which aren't changed, so you can have a very small subset of the schema, only including fields which you want to update. Always keep in mind the performance overhead: calling UpdateRecords() sends your dataset's XML schema and content inside a SOAP packet to the Groove localhost web server, which unwraps the XML and processes it, so it's worthwhile keeping an update schema as small as practicable.