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(
"Selection
Namespaces
", '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:myFie
lds/my:gro
up4");
var iPos = 1;
var xmlNodes2 = XDocument.DOM.selectNodes(
"/my:myFie
lds/my:grp
ImpairList
");
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:ItemNum
ber").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:ItemNum
ber2").tex
t = 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::OnAfterCh
ange(event
Obj)
{
// 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:
grpImpairL
ist
// Note: Information in this comment is not updated after the function handler is created.
//=======
function msoxd_my_grpImpairList::On
AfterChang
e(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