Book a Demo

Author Topic: Traversing a List with more than 3 levels  (Read 3279 times)

Verdant Force

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Traversing a List with more than 3 levels
« on: September 26, 2013, 11:25:35 am »
I'm working on enhancing an excel spreadsheet consisting of information for business usage regarding applications.

We have a list of organisational units that go down 3-4 levels e.g.

A --
   AA
       --
          AAA
                 --
                     AAAA

I have some code that gets the first level of the org unit (A) this is not a problem, though I'm new to Enterprise Architect and don't know the API all that well, but I am perservering the trouble is i'm trying to traverse from one connector to another to get to the next levels properties. I can't seem to find the name of the next connector within intellisense so i can't access the objects properties in subsequent levels, here is what I have came up with so far. Another note is that subsequent levels are also called OrganizationUnit. Some help will be appreciated.

function savePAGE(oWB, app, guid, store)
{      
      var entry = new Object();
      var oSheet  = oWB.Worksheets.Add;
            oSheet.Name  = app;

      var elem as EA.Element;
            elem = Repository.GetElementByGuid(guid);
      
      var rng = oSheet.Range("A1");
      var hyperlinkTargetAddress =  "'INDEX'!A1";
      var str = "";

r++;
r++;
    
oSheet.Cells(r, 1).Value     = "THIS IS A TEST";
oSheet.Cells(r, 1).Font.Bold = 'TRUE';        

for(var N = 0; N < elem.Connectors.Count; N++)
   {
        var flow as EA.Connector;
              flow = elem.Connectors.GetAt(N);
            
        var sElem as EA.Element;
              sElem = Repository.GetElementByID(flow.SupplierID);
            
        var cElem as EA.Element;
              cElem = Repository.GetElementByID(flow.ClientID);            
            
           if(elem.ElementID != flow.SupplierID)
           {
      if( sElem.Stereotype == "OrganizationUnit" ) {
          oSheet.Cells(r, 1).Value = sElem.Stereotype;
          oSheet.Cells(r, 2).Value = sElem.Name;                        
          entry.UNIT = sElem.Name;
          r++;
                }
            }

            if(elem.ElementID != flow.ClientID)
            {
       if( cElem.Stereotype == "OrganizationUnit" ) {
           oSheet.Cells(r, 1).Value = cElem.Stereotype;
           oSheet.Cells(r, 2).Value = cElem.Name;
           entry.UNIT = cElem.Name;
           r++;
      }
            }                              
   }

   store[app] = entry;
   return store;      
}
« Last Edit: September 26, 2013, 11:26:55 am by mscully »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Traversing a List with more than 3 levels
« Reply #1 on: September 26, 2013, 03:59:39 pm »
Hi,

I looked at your code and your question, but I don't understand what your problem is.

Could you please indicate where exactly you are having issues?

Geert

Verdant Force

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Traversing a List with more than 3 levels
« Reply #2 on: September 26, 2013, 04:22:10 pm »
Hi Geert,

Thanks for your reply.

In EA we have uploaded a series of organisational units into EA via a spreadsheet (csv), now I want to iterate through this information there is four levels of it.

As an Example:

<<OrganisationalUnit>> Information
   A.CS.INF
       <<OrganisationUnit>>Information Applications Management
             A.CS.INF.IAP
                <<OrganisationUnit>>Analysis Development Support
                <<OrganisationUnit>>Database Middleware and Releases
                <<OrganisationUnit>>Web Applications
                A.CS.INF.TST
                    <<OrganisationUnit>> Applications Testing

The code provided only gets the value (Information). I would like to get the subsequent structure values into separate variables or an array would suffice these being from structures A.CS.INF.IAP and A.CS.INF.TST

The purpose of this code is to derive which functional area an application belongs too, all the code to grab the applications etc and other information has already been done. Just never have had to delve down 4 or more layers before to grab information out of EA, its new territory for me.

Hope this helps.
« Last Edit: September 26, 2013, 04:26:00 pm by mscully »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Traversing a List with more than 3 levels
« Reply #3 on: September 26, 2013, 05:36:12 pm »
You have to traverse the EA.Element.Elements to find the nested elements.

Geert