Creating a New Discussion Topic and Response Example
Applies to: SharePoint Workspace 2010 | Visual Studio 2008
This sample code shows how to create a topic and response record in the Discussion tool. The same logic can be used to create a parent and child record in any Forms tool.
// Test that tool is Customizable Discussion tool
// Call QueryRecords to get schema
GrooveForms2.RecordQuery recordQuery =
new GrooveForms2.RecordQuery();
recordQuery.QueryMetadataOnly = true;
...
// Query for schema only
GrooveForms2.Forms2RecordDataSet forms2DsSchema =
forms2Svc.QueryRecords(recordQuery);
// Convert the Forms2RecordDataSet to a System.Data.DataSet
// There are no data records in the DataSet
System.Data.DataSet discussionDataSet = null;
FormsRecordDataSet2DataSet(forms2DsSchema, out discussionDataSet);
// Get the forms for Topic and Response by calling ReadForms
GrooveForms2.Form topicForm = ...;
GrooveForms2.Form responseForm = ...;
// Get the schema names from the forms
string topicSchemaName = topicForm.FormsRecordDataSet_ID;
string responseSchemaName = schemaForm.FormsRecordDataSet_ID;
// Create a new DataRow for the new topic entry
DataRow newDataRow =
discussionDataSet.Tables[topicSchemaName].NewRow();
// Set the Subject and Body columns
newDataRow["Subject"] = "Test discussion entry";
newDataRow["Body"] = "Testing adding records to Discussion tool";
// Add the new row to the empty discussionDataSet
discussionDataSet.Tables[topicSchemaName].Rows.Add(newDataRow);
// Table should have child for the attachment fields, but check anyway
if (discussionDataSet.Tables[topicSchemaName].ChildRelations.Count > 0)
{
// Create child entry so it is possible to add attachments
DataRelation relationForAttachProp =
discussionDataSet.Tables[topicSchemaName].ChildRelations[0];
DataTable attachPropTable = relationForAttachProp.ChildTable;
DataRow attachPropTableRow = attachPropTable.NewRow();
attachPropTable.Rows.Add(attachPropTableRow);
// set Parent row
attachPropTableRow.SetParentRow(newDataRow);
// Create attachment here
}
discussionDataSet.AcceptChanges();
// Convert ADO.NET DataSet back to Forms2RecordDataSet
GrooveForms2.Forms2RecordDataSet forms2DSTopic =
DataSet2FormsRecordDataSet(discussionDataSet);
// Now create the record
string[] createdRecordURIs = forms2Svc.CreateRecords(forms2DSTopic);
// Need to read the record to get the double _RecordID value
GrooveForms2.Forms2RecordDataSet createdTopicRecords =
forms2Svc.ReadRecords(createdRecordURIs, false,
false);
// Convert to ADO.NET DataSet
System.Data.DataSet createdTopicDataSet = null;
FormsRecordDataSet2DataSet(createdTopicRecords, out createdTopicDataSet);
// Get _RecordID value from first topic record
double topicID =
(double) createdTopicDataSet.Tables[topicSchemaName].Rows[0]["_RecordID"];
// Now repeat these steps to create a new Response entry
...
// Set the ParentID to the RecordID of the topic record
newResponseRow["_ParentID"] = topicID;
...
See Also
Reference
GrooveForms2.CreateRecords Operation
Concepts
Using ADO.NET DataSets to Access Forms2RecordDataSet Data
Converting Forms2RecordDataSet to ADO.NET DataSet Example