Hi everyone,
I'm trying to make a table dynamically using the referenced code, my problem is that when the “XDocument.DOM.documentElement.appendChild(questionClone);” line is executed a alert message is throw in the form window with this content: "A calculation in the form has not been completed. The number of calculations used for a single action exceeded the maximum limit.". It’s not a javascript error but I have been reading another post about some topic like this and I couldn’t to find out the solution.
I could to see that if the “for (i = 0; i<nodes.childNodes.length; i++)” loop do less than 7 iterations, the message is not showed. By other way the table is always filled, with error or without it and all goes right after that.
Can you help me?
Thanks.
PD. I'm using Infopath2003
EDIT: If "row.selectSingleNode("my:XHTMLQuestion/my:QuestionDesc").appendChild(xmlDoc.documentElement.cloneNode(true));" is changed by something like : "row.selectSingleNode("my:XHTMLQuestion/my:QuestionDesc").text = "test"", the error not happend
function msoxd_my_ProcedureID_attr::OnAfterChange(eventObj)
{
var nodes = domQaA.selectNodes("/dfs:myFields/dfs:dataFields/tns:GetQuestionsAndAnswersResponse/tns:GetQuestionsAndAnswersResult/NewDataSet/Procedures/Questions");
var row, xmlDoc, div;
xmlDoc = XDocument.CreateDOM();
var questionClone = XDocument.DOM.documentElement.childNodes[1].cloneNode(true);
questionClone.removeChild(questionClone.childNodes[1]);
questionClone.removeChild(questionClone.childNodes[0]);
for (i = 0; i<nodes.childNodes.length; i++)
{
row = XDocument.DOM.documentElement.childNodes[1].childNodes[1].cloneNode(true);
var answerRows = row.selectNodes("my:Answers/my:XHTMLAnswer")
var answersNodes = nodes[i].selectNodes("Answers");
var answerRow = answerRows[0];
var answDiv, ansXMLDoc;
for (j = 0; j<answersNodes.length; j++)
{
if(answersNodes[j].selectSingleNode("COMMENTS")!=null)
answerRow.selectSingleNode("my:XHTMLComment").text = answersNodes[j].selectSingleNode("COMMENTS").text;
else
answerRow.selectSingleNode("my:XHTMLComment").text ="";
answerRow.selectSingleNode("my:Score").text = answersNodes[j].selectSingleNode("ANSWERVALUE").text;
answerRow.selectSingleNode("my:Description").text = answersNodes[j].selectSingleNode("ANSWERDESC").text;
answerRow.attributes[0].text = answersNodes[j].selectSingleNode("ANSWERORDER").text;
row.selectSingleNode("my:Answers").appendChild(answerRow.cloneNode(true));
}
row.selectSingleNode("my:Answers").removeChild(row.selectSingleNode("my:Answers").childNodes[1]);
row.selectSingleNode("my:Answers").removeChild(row.selectSingleNode("my:Answers").childNodes[0]);
row.selectSingleNode("my:XHTMLQuestion").attributes[0].text = nodes[i].selectSingleNode("QUESTIONORDER").text;
row.selectSingleNode("my:QuestionID").text = nodes[i].selectSingleNode("QUESTIONID").text;
div ="<div xmlns=\"http://www.w3.org/1999/xhtml\">" + nodes[i].selectSingleNode("QUESTIONDESC").text + "</div>";
xmlDoc.loadXML(div);
row.selectSingleNode("my:XHTMLQuestion/my:QuestionDesc").appendChild(xmlDoc.documentElement.cloneNode(true));
questionClone.appendChild(row.cloneNode(true));
}
XDocument.DOM.childNodes[3].removeChild(XDocument.DOM.documentElement.childNodes[1]);
XDocument.DOM.documentElement.appendChild(questionClone);
}