I am a newbie to coding in Infopath. All of my previous forms relied on rules to get the desired result. I have used an example to submit all the data in a repeating table to sharepoint successfully. The problem is, not all rows in the repeating table should be submitted. I have added a dropdown list with YES or NO in the first column of the repeating table. Any rows that have YES selected in the dropdown should be submitted to sharepoint. This almost works correctly except the IF statement validates against the first row in the repeating table and uses that for the basis of whether or not to submit the entire list as compared to only the items selected within the list. Basically, if my first row has NO selected, the list won't submit, if it has YES selected, it will submit, but still submit's the entire table, not specific rows. I also need to ensure that there are no null fields before submitting. Any help is greatly appreciated.
public void CTRL499_15_Clicked(object sender, ClickedEventArgs e)
{
try
{
// Get a reference to the form's XmlNamespaceManager object.
XmlNamespaceManager ns = this.NamespaceManager;
// Create a DataSource object for the MyContacts
// list data connection.
DataSource dsContacts = this.DataSources["NEW SCR SUBMITTED XML QUERY"];
// Create an XPathNavigator object for the MyContacts
// data connection.
XPathNavigator xnContacts = dsContacts.CreateNavigator();
// Create an XPathNodeIterator object for the MyContacts
// data connection to enumerate the existing contacts.
XPathNodeIterator xiContacts = xnContacts.Select("/xml/rs:data/z:row", ns);
// Create a DataSource object for the Add List Item Template
// data connection.
DataSource dsCAML = this.DataSources["Add List Item Template2"];
// Create an XPathNavigator object for the
// Add List Item Template data connection.
// This is used to set the values in the CAML XML file.
XPathNavigator xnCAML = dsCAML.CreateNavigator();
// Create a WebServiceConnection object for submitting
// to the Lists Web service data connection.
WebServiceConnection wsSubmit =(WebServiceConnection)this.DataConnections["SCR Web Service Submit"];
// Create an XPathNavigator object for the form's
// main data source.
XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
// Create an XPathNodeIterator object for the new contacts.
XPathNodeIterator xiNewContacts = xnDoc.Select("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP", ns);
while (xiNewContacts.MoveNext())
{
// Read only rows where the Changed dropdown list equals YES
if (xiNewContacts.Current.SelectSingleNode("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP/my:Changed", ns).Value == "YES")
{
//Ensure that the Submitter field is not blank.
if (xiNewContacts.Current.SelectSingleNode("/my:myFields/my:SPM/my:SPM_INPUTS_MILESTONES_GROUP/my:Submitter", ns).Value != "")
// Set the values in the Add List Item Template
// XML file using the values in the new row.
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Project_Number']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Project_Number", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Submitter']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Submitter", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Place']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Place", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Site']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Site", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Location']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Location", ns).Value);
// Set the value of Cmd attribute to "New".
xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns)
.SetValue("New");
// Submit the new row.
wsSubmit.Execute();
}
}
}
catch (Exception ex)
{
MessageBox.Show("The following error occurred: " + ex.Message);
throw;
}
}