Advertisement

07.05.2007 at 09:48PM PDT, ID: 22678550
[x]
Attachment Details

InfoPath forms:  how to create an autonumber for multiple repeating sections and tables

Asked by edsager in Microsoft Office Suite, .Net Editors & IDEs, JScript

Tags: , , ,

I have a form made in InfoPath 2007.  It has several repeating sections and tables.  I need to add autonumbers which increase with each addition/insertion of a new table in the repeating table group.  I have been able to adapt the coding I found at: http://radio.weblogs.com/0131777/stories/2004/02/22/howToCreateAnAutonumberField.html to fit my needs for only one repeating table.  I have tried to adapt it for more than one repeating table, but it just does not seem to work.

The code is in JScript and I am using the MS Script Editor, though I am not averse to suggestions for other, better editors.  I am unsure if Adobe CS3 Web Premium has sufficient capability to handle this situation, but I also have that software.

Nor am I averse to using VBScript or anything else, so long as I do not have to become an expert in the language.

Any help is greatly appreciated.

Thank you,
edsager

The code is:

/*
 * This file contains functions for data validation and form-level events.
 * Because the functions are referenced in the form definition (.xsf) file,
 * it is recommended that you do not modify the name of the function,
 * or the name and number of arguments.
 *
*/

// The following line is created by Microsoft Office InfoPath to define the prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-07T00:52:56"');
//</namespacesDefinition>
var fInsideEnsure = false;

// autonumber sets "ItemNumber" text to position of repeating section
function autonumber()
{

      // protect from reentrancy from validation handlers
      if (fInsideEnsure) return;
      fInsideInsure = true;
      
      // select nodes and initialize counter
      var xmlNodes = XDocument.DOM.selectNodes("/my:myFields/my:group4");
      var iPos     = 1;
      var xmlNodes2 = XDocument.DOM.selectNodes("/my:myFields/my:grpImpairList");
      var iPos2     = 1;

      // set counter for each row
      for (var xmlNode = xmlNodes.nextNode(); xmlNode != null; xmlNode = xmlNodes.nextNode())
      {
            // set text of text node to position of an repeating section.
            xmlNode.selectSingleNode("my:ItemNumber").text = iPos++;
      }
      for (var xmlNode2 = xmlNodes2.nextNode(); xmlNode != null; xmlNode = xmlNodes2.nextNode())
      {
            // set text of text node to position of an repeating section.
            xmlNode.selectSingleNode("my:ItemNumber2").text = iPos2++;
      }

      
      fInisdeInsure = false;
}



//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /my:myFields/my:group4
// Note: Information in this comment is not updated after the function handler is created.
//=======
function XDocument::OnLoad(eventObj)
{
      // call autonumber
      autonumber();
}

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /my:myFields/my:group4
// Note: Information in this comment is not updated after the function handler is created.
//=======
function msoxd_my_group4::OnAfterChange(eventObj)
{
// Write code here to restore the global state.

      if (eventObj.IsUndoRedo)
            {
                  // An undo or redo operation has occurred and the DOM is read-only.
                  return;
            }

// A field change has occurred and the DOM is writable. Write code here to respond to the changes.
      if (eventObj.Site != eventObj.Source)
            {
            // Only re-number when a row has been deleted or added.
            // always ignore when just the values of a child nodes change.
            return;
            }

      // Renumber only after add/remove
      autonumber();
}

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /my:myFields/my:group9
// Note: Information in this comment is not updated after the function handler is created.
//=======


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /my:myFields/my:group9/my:grpImpairList
// Note: Information in this comment is not updated after the function handler is created.
//=======
function msoxd_my_grpImpairList::OnAfterChange(eventObj)
{
// Write code here to restore the global state.

      if (eventObj.IsUndoRedo)
            {
                  // An undo or redo operation has occurred and the DOM is read-only.
                  return;
            }

// A field change has occurred and the DOM is writable. Write code here to respond to the changes.
      if (eventObj.Site != eventObj.Source)
            {
            // Only re-number when a row has been deleted or added.
            // always ignore when just the values of a child nodes change.
            return;
            }

      // Renumber only after add/remove
      autonumber();

}
Start Free Trial
 
Loading Advertisement...
 
[+][-]07.06.2007 at 06:29AM PDT, ID: 19431585

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Office Suite, .Net Editors & IDEs, JScript
Tags: infopath, autonumber, repeating, table
Sign Up Now!
Solution Provided By: edsager
Participating Experts: 1
Solution Grade: B
 
 
[+][-]07.06.2007 at 07:14AM PDT, ID: 19431890

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.06.2007 at 01:37PM PDT, ID: 19434851

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32