Book a Demo

Author Topic: Model Add-in (non-blocking) errors  (Read 23568 times)

ppeeters

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Model Add-in (non-blocking) errors
« on: February 03, 2026, 12:49:47 am »
Hi,

I'm new to model add-ins and tried to implement a javascript addin the is triggered on EA_OnPostNewElement to fill in a specific tagged value of elements of a given stereotype (defined using an MDG).

I cannot get rid of an error that occurs while retrieving the element being created:

Part of the code of the EA_OnPostNewElement reception method start with

Code: [Select]
// Configuration
var STEREOTYPE_NAME = "TEA_Capability"; // Stereotype to be catched
var TAGGEDVALUE_NAME = "Capability ID"; // Tagged value name
var ID_PREFIX = "CAP"; // ID prefix
// Extract ID from Info
var elementId, newElement;
elementId = Info.Get("ElementID");
newElement = Repository.GetElementByID(elementId);
if (newElement) {
    if (newElement.Stereotype != STEREOTYPE_NAME) {
        return false;
    }
    // Check if tagged value already exists and has a value
    var tvs = newElement.TaggedValues;

The method is invoked when creating a new element of the given stereotype but it outputs the message:
Code: [Select]
Invocation error in: addin.EA_OnPostNewElement
------------------------------------------------
  12:    // Extract ID from Info
  13:    var elementId, newElement;
  14:    elementId = Info.Get("ElementID");
  15:    newElement = Repository.GetElementByID(elementId);             [!!!! Exception in GetElementByIDInternal application error.]
  16:    if (newElement) {
  17:        if (newElement.Stereotype != STEREOTYPE_NAME) {
  18:            return false;
  19:        }
  20:        // Check if tagged value already exists and has a value
--------------------------------------------------

However the method completes succefully and the tagged value is updated as expected.

I'm using EA v17.0

Any idea what the problem might be ?

Thanks

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Model Add-in (non-blocking) errors
« Reply #1 on: February 03, 2026, 01:30:07 am »
Try this code to replace your lines 13,14 and 15

Code: [Select]
var itemID = Info.Get(0);
var theElement = Repository.GetElementByID(itemID);

Phil
Models are great!
Correct models are even greater!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Model Add-in (non-blocking) errors
« Reply #2 on: February 03, 2026, 01:55:10 am »
This works for me

Code: [Select]
// get element id from event properties
var elementId = Info.Get("ElementID").Value;

// load the element
var element = Repository.GetElementByID(elementId);

The .Value is apparently needed here

Geert

ppeeters

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Model Add-in (non-blocking) errors
« Reply #3 on: February 03, 2026, 10:07:24 pm »
I did try both proposals and they both give the same error while providing a correct result.
However I have narrowed down the problem to the creation element with a stereotype from an added model MDG.
I've tried with the stock APM MDG than can be build with v17 and it gives the same error if a use one of the stereotype defined in the MDG.
If I create a new simple UML class, there is no error.

It looks like a "bug" then even though the script is succefully executed.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Model Add-in (non-blocking) errors
« Reply #4 on: February 06, 2026, 08:34:52 am »
The .Value is apparently needed here

Info is an EventProperties, all of the members are instances of EventProperty. So, yes if you don't add the .Value you are passing a dispatch object back into a function that expects an integer.

I did try both proposals and they both give the same error while providing a correct result.

I would trace the value and type of the elementId and its type and double check that you have reloaded that add-in after making a change.

Code: [Select]
elementId = Info.Get("ElementID").Value;
Repository.WriteOutput("System", typeof elementId + " - " + elementId, 0);
newElement = Repository.GetElementByID(elementId);

To ensure the add-in is reloaded, turn it off in the add-ins window and back on or reload the model.