One great feature of SharePoint and versioning is the ability to have versioned comments. This can allow a small discussion to occur on almost any item. It also allows someone to keep a running log of notes on certain items.
I had the wonderful task of figuring out how to get this to work the same in InfoPath. Below is a function that will append the notes into a repeating group. On submit of the form, I call this function and it works great, everytime!
public void AddAnalystNotes()
{
try
{ //this is the text box the user enters their notes into.
if (GetNodeValue(GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes") != "")
{ //this is the group in the datasource just above the repeating group
XPathNavigator selReqs = MainDataSource.CreateNavigator().SelectSingleNode(
GetRootNodeName() + "/my:DetailsSection/my:AnalystNotesGroup", NamespaceManager);
string nsPrefix = selReqs.Prefix;
string nsURI = selReqs.NamespaceURI;
//this is the repeating group of notes
XPathNodeIterator selAnalyst = MainDataSource.CreateNavigator().Select(
GetRootNodeName() + "/my:DetailsSection/my:AnalystNotesGroup/my:AnalystNotes", NamespaceManager);
XmlWriter writer;
//if there are already items in the list, pop this new note at the top
if(selAnalyst.Count > 0){
selReqs.MoveToChild("AnalystNotes",nsURI);
writer = selReqs.InsertBefore();
}else{
writer = selReqs.AppendChild();
}
//now write the values
writer.WriteStartElement(nsPrefix, "AnalystNotes", nsURI);
writer.WriteElementString(nsPrefix, "CreatedDate", nsURI, DateTime.Now.ToString());
writer.WriteElementString(nsPrefix, "CreatedBy", nsURI, SPContext.Current.Web.CurrentUser.Name);
writer.WriteElementString(nsPrefix, "Notes", nsURI, ""); //have to create a blank entry then add the value later down the line
writer.WriteEndElement();
writer.Close();
//gets the text box with the new notes in it
XPathNavigator xnotes = MainDataSource.CreateNavigator().SelectSingleNode(
GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes",NamespaceManager);
selAnalyst.MoveNext(); //grab the first element, the default is root
//had to use InnerXml, the value to value loses HTML formatting
selAnalyst.Current.SelectSingleNode("my:Notes",NamespaceManager).InnerXml = xnotes.InnerXml;
//clears the text box
SetNodeValue(GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes", "");
}
}
catch (Exception ex)
{
WriteErrorToLog("addRequestor_Click", "Adding analyst noteserrored", ex);
}
}
Then in the view, format the repeating group to be read-only and blamo, versioned comments.
0822e798-92e9-44b6-879d-fb4d43023674|1|5.0