Infopath Form - Cannot generate a new Report Number - InfoPath Dev
in

InfoPath Dev

Infopath Form - Cannot generate a new Report Number

Last post 03-13-2011 07:50 PM by explosive0. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-27-2011 05:10 PM

    Infopath Form - Cannot generate a new Report Number

    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. CDR1900069

    int 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;

    }

  • 03-13-2011 07:50 PM In reply to

    Re: Infopath Form - Cannot generate a new Report Number

     Easier way without having to write custom code

     http://www.bizsupportonline.net/browserforms/autonumber-infopath-form-submitted-sharepoint-library.htm

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.