Book a Demo

Author Topic: JavaScript appendChild problem  (Read 13762 times)

stereotype

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
JavaScript appendChild problem
« on: April 28, 2020, 12:06:29 am »
Trying to do some fragment scripting, I am looking at the example in the user guide https://sparxsystems.com/enterprise_architect_user_guide/15.1/model_publishing/example_rtf_template_fragment_.html but instead of JScript I try to use JavaScript (which I think is the recommendation?).

So instead of

Code: [Select]
var xmlDOM = new ActiveXObject("MSXML2.DOMDocument.4.0");
I write

Code: [Select]
var xmlDOM = new COMObject("MSXML2.DOMDocument");
Now, the first two "xmlDOM.appendChild" in the example seems to work fine
Code: [Select]
...
xmlDOM.appendChild(node);
...
xmlDOM.appendChild(xmlRoot);
...

but

Code: [Select]
xmlRoot.appendChild(xmlDataSet);
gives an error message: "xmlRoot.appendChild is not a function"

According to an old topic https://www.sparxsystems.com/forums/smf/index.php/topic,38371.0.html there was a confirmed issue around this - is that issue still not fixed or am I doing something wrong?

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: JavaScript appendChild problem
« Reply #1 on: April 28, 2020, 10:27:37 am »
Which version of Enterprise Architect are you running? The JavaScript engine had a major update in EA 15 which resolved a number of problems like this. So if not running EA 15 or higher, you might need to update.

stereotype

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: JavaScript appendChild problem
« Reply #2 on: April 28, 2020, 05:15:10 pm »
I am running EA 15.0.1513

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: JavaScript appendChild problem
« Reply #3 on: April 29, 2020, 09:33:38 am »
It's not clear what type of objects xmlRoot or xmlDataSet are in your examples so far.

Can you perhaps send a complete copy of your script (or sample model file) to our support email for further investigation?
Send to: [email protected]

Or otherwise perhaps post a more complete code sample here on the forum which demonstrates the problem?

stereotype

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: JavaScript appendChild problem
« Reply #4 on: April 30, 2020, 04:35:57 pm »
As I wrote, I copied the example from the user guide (link above) to my JavaScript script and changed "new ActiveXObject("MSXML2.DOMDocument.4.0")" to "new COMObject("MSXML2.DOMDocument")"

Code: [Select]
!INC Local Scripts.EAConstants-JScript

function myFunctionName (objectID)

{
var xmlDOM = new COMObject("MSXML2.DOMDocument");

xmlDOM.validateOnParse = false;
xmlDOM.async = false;

var node = xmlDOM.createProcessingInstruction("xml", "version='1.0' encoding='ISO-8859-1'");
xmlDOM.appendChild(node);

var xmlRoot = xmlDOM.createElement("EADATA");
xmlDOM.appendChild(xmlRoot);

var xmlDataSet = xmlDOM.createElement("Dataset_0");
xmlRoot.appendChild(xmlDataSet); /* Error message when this row is executed */
:
:


Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: JavaScript appendChild problem
« Reply #5 on: May 01, 2020, 05:06:38 pm »
Sorry, I missed missed the page where you had initially taken the script from. Having copied the original script from that page, replaced the ActiveXObject line with COMObject like you describe, unfortunately I couldn't reproduce your error. The script seemed to execute fine for me as JavaScript. Tested with EA 15.0.1514 and 15.1.1528. I was only testing running the script directly from the Scripting window however, I was not attempting to invoke it from a script fragment.