Book a Demo

Author Topic: append attribute note to attribute name  (Read 3733 times)

peternees

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
append attribute note to attribute name
« on: June 03, 2010, 11:36:21 pm »
I did a reverse engineering of an iSeries DB to EA, which worked fine. However tehre is one problem: the <<column>>attribute names are the technical column names, and the logical column name is generated in the <<column>>attribute note. The <<column>>attribute not can apparently not be visualised on the class diagram, which makes my diagram uncomprehensable.
So I want to move the note value to the name property (or append it it).
How could I do this?

ps: I have no experience with scripting, and am not even sure I need it for my problem.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: append attribute note to attribute name
« Reply #1 on: June 04, 2010, 03:35:04 pm »
Hi,

The best way would be to write a little program/script to manipulate the name/notes of your columns.
Summarized the code should look something like this:
(disclaimer: written from memory, not tested)
Code: [Select]
EA.Package myPackage = Repository.GetTreeSelectedPackage();
foreach (EA.Element myElement in myPackage.Elements)
{
    foreach (EA.Attribute myAttribute in myElement.Attributes()
    {
        myAttribute.Name = myAttribute.Name + "_" + myAttribute.Notes;
        myAttribute.Update();
    }
}

If you really want you could also update the database directly, but I would advise against that.

Geert

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: append attribute note to attribute name
« Reply #2 on: June 04, 2010, 03:41:12 pm »
Be careful of foreach in JScript (from memory) it actually goes over all members in the structure, not all elements in a collection.

If you want foreach functionality you have to use enumerators (See JScript - Recurisve Model Dump Example in the example script library for an example on using enumerators).
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

peternees

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: append attribute note to attribute name
« Reply #3 on: June 05, 2010, 12:31:07 am »
bedankt! code werkt :

Code: [Select]
function main()
{
      myPackage = Repository.GetTreeSelectedPackage();
      for(var i=0; i < myPackage.Elements.Count; i++)    
      {
            myElement = myPackage.Elements.GetAt(i);
      
            for(var j=0; j < myElement.Attributes.Count; j++)
            {
                  myAttribute = myElement.Attributes.GetAt(j);
                  myAttribute.Name = myAttribute.Notes + " (" + myAttribute.Name + ")" ;
                  myAttribute.Update();
            }
      }
}

main();