Insert data into repeating table through script

Q

Queezy

I am using code created by Joey Allen [MSFT] (posted below), and I can
get it to work on my form/namespace when accessing the main table of
my Main data connection. But I am trying to copy data from a nested
table within the Main data connection. For instance, using Joey's
code below, his data connection is called "titleview", and the xpath
is "/dfs:myFields/dfs:dataFields/d:titleview". I would like to copy
from the same data connection, but from something like - "/
dfs:myFields/dfs:dataFields/d:titleview/d:titledetails". Anybody know
how I could alter this code to do this?



function UpdateTitleList()
{
//Get a reference to the Titles group in the main data source
var objTitles = XDocument.DOM.selectSingleNode("/my:myFields/
my:Titles");


//Clear the AvailableTitles node
var objAvailableTitles =
objTitles.selectNodes("my:AvailableTitle");
objAvailableTitles.removeAll();


//Set the "SelectNamespaces" property so we can do selectNodes
calls on
the titleview DOM

XDocument.DataObjects("titleview").DOM.setProperty("SelectionNamespaces",


'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/
dataFormSoluti
on"
xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/
dataFields"
' );


//Get a reference to the list of titles
var objTitleViewTitles =
XDocument.DataObjects("titleview").DOM.selectNodes(
"/dfs:myFields/dfs:dataFields/d:titleview" );


//enumerate the TitleViewTitles, and add a AvailableTitles for
each one
for (i=0; i < objTitleViewTitles.length; i++)
{
//Create a new XML node with the right name and namespace
var newAvailableTitle = XDocument.DOM.createNode( 1,
"AvailableTitle",


"http://schemas.microsoft.com/office/infopath/2003/myXSD/
2003-05-06T18...
" );


//Copy the value of the "title" attribute into the new
node
newAvailableTitle.text =
objTitleViewTitles.item(i).selectSingleNode(
"@title" ).text;


//Add the new node to the Titles group
objTitles.appendChild( newAvailableTitle );
}


//Force the view to refresh
XDocument.View.ForceUpdate();



}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top