OK,
I have my proof of concept developed.
The code consists of two parts.
The "On Load" event will save the XML for reinitialization.
The original idea was presented in the below link. Big thanks to the author.
// reset solution private variable as defined in the below link:
//http://www.bizsupportonline.net/blog/2009/08/clear-reset-fields-infopath-3-lines-code/
The "Copy" Button(my custom code),
1.) Save a sampling of non key fields from each table.(that's why this is a proof of concept).
2.) Replace the Saved "On Load" XML. All the data fields are set back to Blanks.
3.) Update the columns from step 1.
Below is the code that supports the proof of concept.
The next phase is to eliminate the "On Load" Event code.
When the user clicks the "Copy" Button, retrieve the XML.
Blank out each of the identity columns.
Reload the XML back to InfoPath.
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
// initialData = MainDataSource.CreateNavigator().SelectSingleNode("//my:container", NamespaceManager).OuterXml;
initialData = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update", NamespaceManager).OuterXml;
}
public void CTRL114_7_Clicked(object sender, ClickedEventArgs e)
{
// Create XPathNavigator positioned at the root of the main data
// source.
XPathNavigator myNav = this.MainDataSource.CreateNavigator();
// Select employee field and set value to username.
XPathNavigator nav = MainDataSource.CreateNavigator();
// save form fields to temporary variables
string tmpIPD_Description = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/@IPT_Description", NamespaceManager).ToString();
string tmpIPT_Lead = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/@IPT_Lead", NamespaceManager).ToString();
string tmpSubmission_Date = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Submission_Date", NamespaceManager).ToString();
//Clear Key values
string tmpProject_Status___Duration = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Project_Status___Duration", NamespaceManager).Value;
string tmpProject_Status___Effort = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Project_Status___Effort", NamespaceManager).Value;
string tmpDays_Ahead_Behind = nav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Days_Ahead_Behind", NamespaceManager).Value;
// Retrieve the rows of the TMD_Update child table
string[] arTask_Status = new string[100];
string[] arHigh_Level_Description = new string[100];
string[] ar__Complete = new string[100];
//Loop through all the TMD rows
int TMDCount = 0;
XPathNodeIterator TMD_rows = nav.Select("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/d:TMD_Update", NamespaceManager);
while (TMD_rows.MoveNext())
{
arTask_Status[TMDCount] = TMD_rows.Current.SelectSingleNode("@Task_Status", NamespaceManager).Value;
arHigh_Level_Description[TMDCount] = TMD_rows.Current.SelectSingleNode("@High_Level_Description", NamespaceManager).Value;
ar__Complete[TMDCount] = TMD_rows.Current.SelectSingleNode("@__Complete", NamespaceManager).Value;
TMDCount = + 1;
}
// Retrieve the rows of the AI_Update child table
string[] arAI_Num = new string[100];
string[] arAI_Status = new string[100];
string[] arAI_Description = new string[100];
string[] arAI_Dependencey_impact = new string[100];
int AICount = 0;
XPathNodeIterator AI_rows = nav.Select("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/d:AI_Update",NamespaceManager);
// Loop through the rows of the TMD_Update repeating table and initialize key fields to null
while (AI_rows.MoveNext())
{
arAI_Num[AICount] = AI_rows.Current.SelectSingleNode("@AI_Num", NamespaceManager).Value;
arAI_Status[AICount] = AI_rows.Current.SelectSingleNode("@AI_Status", NamespaceManager).Value;
arAI_Description[AICount] = AI_rows.Current.SelectSingleNode("@AI_Description", NamespaceManager).Value;
arAI_Dependencey_impact[AICount] = AI_rows.Current.SelectSingleNode("@AI_Dependencey_impact", NamespaceManager).Value;
AICount = +1;
}
// Retrieve the rows of the Mgmt_Attention_Update child table
string[] arItem_Num = new string[100];
string[] arDescription = new string[100];
string[] arProbability = new string[100];
string[] arImpact = new string[100];
int MgmtCount = 0;
XPathNodeIterator Mgmt_rows = nav.Select(
"/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/d:Mgmt_Attention_Update",
NamespaceManager);
// Loop through the rows of the TMD_Update repeating table and initialize key fields to null
while (Mgmt_rows.MoveNext())
{
arItem_Num[MgmtCount] = Mgmt_rows.Current.SelectSingleNode("@Item_Num", NamespaceManager).Value;
arDescription[MgmtCount] = Mgmt_rows.Current.SelectSingleNode("@Description", NamespaceManager).Value;
arProbability[MgmtCount] = Mgmt_rows.Current.SelectSingleNode("@Probability", NamespaceManager).Value;
arImpact[MgmtCount] = Mgmt_rows.Current.SelectSingleNode("@Impact", NamespaceManager).Value;
MgmtCount = +1;
}
//Clear all data back to the initial state of the "On Load" event
MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update", NamespaceManager).ReplaceSelf(initialData);
// Update form values from saved columns
XPathNavigator Upd = MainDataSource.CreateNavigator();
// Update headerportion(Teams) Key field with blank IPT ID
Upd.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/@IPT_Description", NamespaceManager).SetValue(tmpIPD_Description);
Upd.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/@IPT_Lead", NamespaceManager).SetValue(tmpIPT_Lead);
Upd.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Project_Status___Duration", NamespaceManager).SetValue(tmpProject_Status___Duration);
Upd.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Project_Status___Effort", NamespaceManager).SetValue(tmpProject_Status___Effort);
Upd.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/@Days_Ahead_Behind", NamespaceManager).SetValue(tmpDays_Ahead_Behind);
//Write back TMP_Update Section
// Loop through the rows of the TMD_Update repeating table and initialize key fields to null
int x = 0;
//'get the node you wish to have repeated
string xpath = "/dfs:myFields/dfs:dataFields/d:Teams/d:CFMS_Update/d:TMD_Update";
XPathNavigator uTMD_rows = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
while (x