We have a infopath form in which there is button called Generate (which generates a new Report Number in the field everytime the new form is opened). but when we click on the button it generates the same report number which is in the format CDR +1900000 +ID. Any ideas or suggestions??
We are using below custom code for the button which should increment the report number.
public void btnGenerate_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.XmlNamespaceManager ns = this.NamespaceManager;
XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
try
{
int currentMax = GetNextID(ns);
//1900000 + ID (Math Operation = e.g. CDR1900069int libUniqueStartNum = 1900000;
int intReportNum = libUniqueStartNum + currentMax;string strReportNum = "CDR" + intReportNum;if (this.New)
{
//xnDoc.SelectSingleNode("/my:myFields/my:reportDetails/my:reportNumber", ns).SetValue(currentMax.ToString());xnDoc.SelectSingleNode("/my:myFields/my:reportDetails/my:reportNumber", ns).SetValue(strReportNum);
}
else
{
xnDoc.SelectSingleNode("/my:myFields/my:reportDetails/my:reportNumber", ns).SetValue("ERROR!!!");
}
}
catch
{
//xnDoc.SelectSingleNode("/my:Main/my:OfficeUse3/my:currentIDMaxPlus1", ns).SetValue(ex.Message);
}
// Create a DataConnection object
// data connection.DataConnection dcCDR = this.DataConnections["Main submit"];
// Execute the data connection
dcCDR.Execute();
}
private int GetNextID(XmlNamespaceManager ns)
{
int currentMax=0;
try
{
// Create a DataSource object for EB Record Requests DataSource dsRecordRequests = this.DataSources["Container Damage Reports"];
XPathNavigator xnRecordRequests = dsRecordRequests.CreateNavigator();
// XPathNodeIterator xiRecordRequests = xnRecordRequests.Select("/dfs:myFields/dfs:dataFields/dfs:EB_Record_Requests", ns);XPathNodeIterator xiRecordRequests = xnRecordRequests.Select("/dfs:myFields/dfs:dataFields/dfs:Container_Damage_Reports", ns);while (xiRecordRequests.MoveNext())
{
int currentID = int.Parse(xiRecordRequests.Current.SelectSingleNode("@ID").Value);if (currentID > currentMax)
{
currentMax = currentID;
}
}
currentMax++;
}
catch
{
throw new Exception("Could not get next ID from sharepoint list: GetNextID(XmlNamespaceManager ns)");
}
return currentMax;
}