Book a Demo

Author Topic: JavaScript to convert an element to an ArchiMate data object  (Read 26473 times)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
JavaScript to convert an element to an ArchiMate data object
« on: February 06, 2026, 10:18:32 pm »
Having asked Copilot to write me a JavaScript to convert an class element to an ArchiMate3 data object, Copilot has generated the function below.

It not only did not work. It tried a number of things I was not expecting, specifically:
  • element.Stereotype = "ArchiMate3::DataObject";
  • element.StereotypeEx = "ArchiMate3::DataObject";
  • element.MetaType = "ArchiMate3::DataObject";
  • Repository.AdviseElementChange(element.ElementID);

The only way to get this to work was to use just 1, and comment out 2 and 3. I also don't understand the purpose of 3 & 4.

It has been a long week and I don't think I have the bandwidth to understand this, perhaps somebody can shed some light on why the AI will add 3 & 4. 2 could just be a case of dumb AI.

Code: [Select]
function convertToArchiMateDataObject(element) {

    Session.Output("   🔄 Converting: " + element.Name);

    //
    // STEP 1 — Clear stereotypes completely
    //
    element.Stereotype = "";
    element.StereotypeEx = "";
    element.Update();


    //
    // STEP 2 — Apply ArchiMate Data Object stereotype correctly
    //
    // EA requires this exact format: <MDG>::<Stereotype>
    //
    element.Stereotype = "ArchiMate3::DataObject";
    element.StereotypeEx = "ArchiMate3::DataObject";

    //
    // STEP 3 — Force MDG meta-type (important!)
    //
    element.MetaType = "ArchiMate3::DataObject";


    //
    // STEP 4 — Save and refresh element
    //
    element.Update();
    Repository.AdviseElementChange(element.ElementID);

    Session.Output("      ✔ Converted to ArchiMate3::DataObject");
}

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: JavaScript to convert an element to an ArchiMate data object
« Reply #1 on: February 06, 2026, 10:57:04 pm »
An update on this.

The modified script has indeed added ArchiMate3::DataObject to the stereotype but it is only visible through the properties dialog. In the properties pane, it is not visible. Furthermore, the Stereotype field is not populated when exporting the data.

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 to convert an element to an ArchiMate data object
« Reply #2 on: February 07, 2026, 06:39:27 pm »
You need to set the stereotypeEx to the correct fully qualified stereotype, and call update() to save it.

Now the problem is that you fumbled the steretoype.
Ther is no such stereotype as DataObject in the ArchiMate3 profile.

It's ArchiMate3::ArchiMate_DataObject

The easiest way to get the 100% correct stereotype name (casing is important) is to use the metatype objet from the Profile toolbox.
There you can choose to create any existing stereotype, and you'll get the full name as it is known by EA.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: JavaScript to convert an element to an ArchiMate data object
« Reply #3 on: February 09, 2026, 05:00:03 pm »
1. element.Stereotype = "ArchiMate3::DataObject";
Attempts to assign a stereotype with the name "ArchiMate3::DataObject" to the object. If it is not already defined it will attempt to define it as a global stereotype. It's less bad if you don't include a profile. As an example, if you specified ArchiMate_DataObject it may assign ArchiMate2::ArchiMate_DataObject or ArchiMate3::ArchiMate_DataObject. Think of it as "I don't care where the stereotype comes from, as long as it has this name".

2. element.StereotypeEx = "ArchiMate3::DataObject";
Attempts to assign the stereotype "DataObject" from the profile "ArchiMate3" to the object. As Geert said, this won't be found because no such stereotype exists in that profile. If you replace it with "ArchiMate3::ArchiMate_DataObject" It will still fail if the element is not a Class.

3. element.MetaType = "ArchiMate3::DataObject";
Does literally nothing.

4. Repository.AdviseElementChange(element.ElementID);
Effectively updates any places in the UI that have that object.
« Last Edit: February 10, 2026, 02:51:36 pm by Eve »

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: JavaScript to convert an element to an ArchiMate data object
« Reply #4 on: February 10, 2026, 09:59:36 pm »
Thank you Eve and Geert, scripts corrected, including adding the right value to stereotypeEx.