Hi friends
I try to programatically use a repeating table in a infopaht form to log State Changes in it. I figured out how to get on the repeating table, but I dont manage to really have it as I like. Always when I ad a child, it changes the first row that I had to clone. I'm using Infopaht 2007 and Visual Studio 2005.
What I want to do: If someone changes the state of my form, or the state is changed by an event, I would like to write this into a repeating table, to log who has changed from what state to what new state with which event and when. e.g. username, open, closed, 2007-09-26T10:05:23
I use this c# code to do this:
private void AdNewRowToStateHistory(string StateChangeEvent, string NewState)
{
XPathNavigator State = MainDataSource.CreateNavigator().SelectSingleNode("//my:txtState", NamespaceManager);
//Repeating TableXmlNamespaceManager nsmgr = NamespaceManager;
XPathNavigator StateHistory = MainDataSource.CreateNavigator().SelectSingleNode("//my:Root/my:StateHistory", nsmgr);XPathNavigator StateHistoryDetail = MainDataSource.CreateNavigator().SelectSingleNode("//my:Root/my:StateHistory/my:StateHistoryDetail", nsmgr);
XPathNavigator newNode = StateHistoryDetail.Clone();newNode.SelectSingleNode("my:rptStateUser",nsmgr).SetValue(System.Environment.UserName);
newNode.SelectSingleNode(
"my:rptStateStateOld", nsmgr).SetValue(Convert.ToString(State));newNode.SelectSingleNode("my:rptStateStateNew", nsmgr).SetValue(NewState);
newNode.SelectSingleNode(
"my:rptStateEvent", nsmgr).SetValue(StateChangeEvent);newNode.SelectSingleNode("my:rptStateTimestamp", nsmgr).SetValue(DateTime.Now.ToString("yyyy.MM.ddThh:mm:ss"));
StateHistory.AppendChild(newNode);
State.SetValue(Convert.ToString(NewState));
}