Programatically add row to a repeating table

M

Mauricio

Hi,

I want to add a new row programatically to a repeating table.
I'm working with FormCode.cs class of .net framework to programming. I've
created IXMLElement to add to IXMLNode object that represents the repeating
table.

i.e.:
IXMLDOMNode docData =
thisXDocument.DOM.selectSingleNode("//my:DocumentsData");
IXMLDOMElement proc = thisXDocument.DOM.createElement("Process");
docData.appendChild(proc);

When Infopath forms runs, a message exception like:
System.Runtime.InteropServices.COMException
Element 'Process' is unexpected according to content model of parent element
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-03-02T18:37:11}DocumentsData'.
Expecting:
{http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-03-02T18:37:11}Process.

Anyone have any idea???
DocumentData Expects Process element, and i pass a process element, but it
does not recongnize.

Any pointers would be really appreciated.
Regards,
Mauricio.-
 
K

KjellSJ

Your problems stems from your XSD using a <sequence> of elements, and the
node you try to append to the end of your XML is not of the same type as the
last element in your XSD.

You cannot append a 'DocumentsData' element at the end, only 'Process'
elements according to your XSD.

Use node.insertBefore instead of node.appendChild (JScript code):

//get first row
var rowOne = XDocument.DOM.selectSingleNode("//s1:InvoiceDetailsRow");
//clone the first row
var rowClone = rowOne.cloneNode(true);
//reset values
rowClone.selectSingleNode("s1:Description").text = "CLONED";
rowClone.selectSingleNode("s1:NetAmount").text = "";
rowClone.selectSingleNode("s1:IsVatCharged").text = 0;
rowClone.selectSingleNode("s1:VatAmount").text = 0;
//append row to XML document
var parent =
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields//s1:Invoice");
parent.insertBefore(rowClone, rowOne);


Hope this helps!
KjellSJ (http://kjellsj.blogspot.com)
 

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