Author Topic: Does EA_GetMenuState actually work in JavaScript?  (Read 1984 times)

MichPaule

  • EA User
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Does EA_GetMenuState actually work in JavaScript?
« on: June 04, 2024, 12:18:05 am »
From what I understand JavaScript parameters always are passed by value.
However the last 2 parameters of EA_GetMenuState are defined as OUT (see https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/eaadd-insea_getmenustate.html).
Does this actually work?
In my Model Add-In experiments I didn't manage to make it work.
Has somebody had success using JavaScript?
TIA

Michael

MichPaule

  • EA User
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Re: Does EA_GetMenuState actually work in JavaScript?
« Reply #1 on: June 04, 2024, 05:13:10 pm »
Found it! :)
The OUT parameters isEnabled and IsChecked are objects instead of Booleans.
Reading/assigning values is accomplished via the object member val e.g. isEnabled.val = false;

Would be worth a remark in the documentation?

Takeshi K

  • EA User
  • **
  • Posts: 562
  • Karma: +35/-1
    • View Profile
Re: Does EA_GetMenuState actually work in JavaScript?
« Reply #2 on: June 04, 2024, 06:16:37 pm »
Hello Michael,

Including your solution, the Example model contains the basic information. It is helpful to start the Model-based addins.
(about 'isEnabled.val = false', we can find the EA_GetMenuState reception of the TypeInfo class in the example model.)

HTH,

--
t-kouno

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Does EA_GetMenuState actually work in JavaScript?
« Reply #3 on: June 05, 2024, 08:23:48 am »
Would be worth a remark in the documentation?
https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/modeladdins-code.html

Quote
Retrieving return values in JavaScript
When handling a reception for an event with OUT/INOUT parameters, values must be read and assigned using the .val attribute of those parameters.

For example, to set the value of the TagValue parameter on the EA_OnElementTagEdit event:

     TagValue.val = "Hello World!"

In short, it's the way Javascript handles parameters. Effectively objects are passed by reference primitives are passed by value. That's not technically correct, but it's close enough to get me going.

If it was only that function then the comment could have been in the documentation for the broadcast. It's not.

MichPaule

  • EA User
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
Re: Does EA_GetMenuState actually work in JavaScript?
« Reply #4 on: June 05, 2024, 03:26:27 pm »
Thanks a lot for the clarification, Eve!
I would not have searched for the info exactly in that place but maybe it's only me...

Michael

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Does EA_GetMenuState actually work in JavaScript?
« Reply #5 on: June 06, 2024, 08:46:36 am »
Which is the perennial problem of writing documentation. You can't document anything where everyone will look. (Partially because at least half don't look at all)