Book a Demo

Author Topic: Javascript calling JScript  (Read 5410 times)

duncan.greenyer

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Javascript calling JScript
« on: October 25, 2022, 12:35:56 am »
I know I can use !INC to include other scripts however the included scripts run in the context of the active scripting engine. How can I call from Javascript to JScript? Why would I want to do this? Well I have a nice OO collection of classes written in Javascript however, I want to use a COM Object that returns a Variant. Javascript doesn't understand Variants but JScript does, but Jscript will not understand the "let" or "class". Anyone got any ideas?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Javascript calling JScript
« Reply #1 on: October 25, 2022, 07:51:52 am »
You can't they are completely different scripting engines.

So, how about you tell me more about what the issue is that makes you want to. There's at least some support for Variants in the Javascript.

duncan.greenyer

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Javascript calling JScript
« Reply #2 on: October 25, 2022, 05:32:02 pm »
Hi Eve,

I am creating an Azure Devops Integration, because of security restrictions I cannot install add-ins etc... so scripting is my best option. I have already created an integration for workitems and it works well allowing me to design Story Maps in EA and send them to DevOps. Now I want to send EA Diagrams, Tables and Text to a DevOps Wiki which I can do, however I have to base64 encode the images and send them as attachments. I can do all of this in JScript using ADODB.Stream etc... however COM Objects and JScript are old technology with inherent security issues etc. The best solution would be for EA to Support V8 Javascript Engine and Node.js but I can't see that happening. I don't want to stick with JScript because it is too procedural, but I can't do everything I want in the WSH Javascript engine. ADODB.Stream read method returns a SAFEARRAY but converting in Javascript every element is 0 which I assume is JS lack of support for VARIANT ARRAYS. So, thinking this through, if Sparx were to implement a GetDiagramAsBase64(diagramID) then all of these problems would go away for now and EA integration with Web Technologies would improve.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Javascript calling JScript
« Reply #3 on: October 26, 2022, 09:49:10 am »
The best solution would be for EA to Support V8 Javascript Engine and Node.js but I can't see that happening.
Yeah, probably not. We've invested in the spidermonkey engine and I'm aware of a compelling reason to switch.

ADODB.Stream read method returns a SAFEARRAY but converting in Javascript every element is 0 which I assume is JS lack of support for VARIANT ARRAYS.
That's probably something you could send an example script to support for us to investigate.


So, thinking this through, if Sparx were to implement a GetDiagramAsBase64(diagramID) then all of these problems would go away for now and EA integration with Web Technologies would improve.
I'm guessing from the context that you're trying to get the saved diagram images from the database. Perhaps Repository.SQLQuery will help since that returns an XML document, any binary fields will already be converted to base64.
https://www.sparxsystems.com/enterprise_architect_user_guide/16.0/add-ins___scripting/repository3.html

duncan.greenyer

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Javascript calling JScript
« Reply #4 on: October 26, 2022, 06:26:45 pm »
I hadn't thought of using SQLQuery to get base64, that's a great idea, will give it a go. Thanks.

duncan.greenyer

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Javascript calling JScript
« Reply #5 on: October 26, 2022, 06:53:15 pm »
Hmmm, thinking about it again, I wouldn't have though diagrams would be stored as images given that diagrams can be edited and therefore are rendered on-the-fly. Therefore SQLQuery isn't going to be able to return the binary data because it is never stored. Or am I wrong?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Javascript calling JScript
« Reply #6 on: October 26, 2022, 06:57:21 pm »
The image can be stored, if you turn on the option Configure | Options | Cloud | Auto create diagram and image map (each time a diagram is saved)

Not sure how it's stored exactly, and whether you can use SQLQuery to get the base64 encoded image.

Geert


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Javascript calling JScript
« Reply #7 on: October 26, 2022, 07:51:35 pm »
The image can be stored, if you turn on the option Configure | Options | Cloud | Auto create diagram and image map (each time a diagram is saved)

Not sure how it's stored exactly, and whether you can use SQLQuery to get the base64 encoded image.

Geert
IIRC it's a Sparx-proprietary format. If you want the image of diagrams you can export them from the API. Takes time and the diagram must be open. But unless you tell us what you want to do really it's all guessing.

q.

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Javascript calling JScript
« Reply #8 on: October 28, 2022, 09:45:07 pm »
I did a test but executing the query "select bincontent from t_document where docname= 'myImage.png'" but I didn't manage to do anything with the returned base64 value (I tried some online Image base64 decoder..)

Do we need EA API to decode the diagram images from the DB stored value ?

Thanks
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Javascript calling JScript
« Reply #9 on: October 29, 2022, 07:54:17 am »
What did I say above?

q.