Book a Demo

Author Topic: Change Diagram Type via JavaScript  (Read 4629 times)

GeordieKiwi

  • EA Novice
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Change Diagram Type via JavaScript
« on: January 10, 2022, 07:51:05 pm »
We have a model with a few hundred diagrams and a few thousand elements in BPMN notation and we want to convert to ArchiMate Notation using a script as it would be too tedious to do manually.

We have managed to convert the elements okay using theElement.Type and theElement.StereotypeEx properties

Code: [Select]
function TypeConversion(sourceType, sourceStereotype, targetType, targetStereotype)
{
    this.sourceType = sourceType;
    this.sourceStereotype = sourceStereotype;
    this.targetType = targetType;
    this.targetStereotype = targetStereotype;
}
var elementConversions = new Array();
elementConversions[0] = new TypeConversion( "Activity", "BusinessProcess","Activity", "ArchiMate_BusinessProcess");
...
   for ( var i = 0 ; i < elementConversions.length ; i++ )
    {
        // If stereotype matches source list then convert
        if ( (theElement.Stereotype == elementConversions[i].sourceStereotype) && (theElement.Type == elementConversions[i].sourceType ))
        {
            theElement.Type = elementConversions[i].targetType;
            theElement.StereotypeEx = elementConversions[i].targetStereotype;
            theElement.Update();
        }
    }
...
Was planning on doing a similar thing with diagrams but discovered that theDiagram.Type contains the basic UML diagrams types like 'Analysis' or 'Logical' instead of the BPMN type "Business Process" or ArchiMate type "Business Layer" as shown in the properties window. The  theDiagram.Stereotype appears not to be used as its empty.

However I found another diagram property called MetaType that appeared to have values such as "BPMN2.0::Business Process" and "Archimate3::Business" so tried the following code

Code: [Select]
//Diagram Conversion Table
var diagramConversions = new Array();
diagramConversions[0] = new TypeConversion("Analysis", "BPMN2.0::Business Process", "Logical", "Archimate3::Business");
...
theDiagram.Type=diagramConversions[i].targetType // "Logical"
theDiagram.MetaType=diagramConversions[i].targetStereotype; //"Archimate3::Business"
        theDiagram.Update();
...

But it didn't seem to work so I've kind of stumped at how to proceed in changing diagram types via Script.

Anyone know how do I change a BMPN diagram to ArchiMate Diagram so I get the ArchiMate Business toolbox come up when I open the diagram?


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change Diagram Type via JavaScript
« Reply #1 on: January 10, 2022, 10:29:09 pm »
Well, yes. But it's not that easy. The diagram type is stored in t_diagram.styleex (you can probably access that through the API, but I always use the direct path). Inside you find a CSV list where one will start with MDGDgm= followed by the "stereotype" of the diagram. You have to alter that. Use a sandbox to first test it. Eventually you can change the diagram type via the GUI.

q.

GeordieKiwi

  • EA Novice
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Re: Change Diagram Type via JavaScript
« Reply #2 on: January 11, 2022, 04:29:48 pm »
Thanks Qwerty hadn't thought of looking in StyleEx

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Change Diagram Type via JavaScript
« Reply #3 on: January 13, 2022, 05:46:00 pm »
Just follow up note. Tried using
theDiagram.StyleEx
But the API doesn't seem to work. Tried all sorts of things such as replace string and just a raw setting to a string but no luck.
Resorted to running a SQL query in JavaScript using Repository.Execute()
Happy to help
:)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change Diagram Type via JavaScript
« Reply #4 on: January 13, 2022, 08:22:27 pm »
Which is why I said eventually above ;-)

q.