Book a Demo

Author Topic: Add-In, C#, MOVE External  (Read 3818 times)

carolin.boeckler

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Add-In, C#, MOVE External
« on: September 30, 2011, 09:43:33 pm »
Hello, I'd like to write a C# Add-in function which looks for requirements (comes from stakeholders/usecases etc) and move these requirements external.
This SQL selection finds all requirements which are not external moved:
            string sql = "SELECT * FROM t_objectrequires";
            col = (EA.Collection)Rep.GetElementSet(sql, 2);
            foreach (EA.Element elem in col)
            {
                ans += elem.Name + " \r\n";
             }
But in elem.Name is written the UseCase-Short Discription and NOT the Name of the requirement. I do not really understand this cause when I use "SELECT * FROM t_objectrequires" in the Model Search Window I get the Name of the requirements (O.K. maybe this part I can manage). Then I'm able to create a new requirement with this Name and make the Connection to the Element "UseCase".
EA.Element statuselement = (EA.Element)pkg.Elements.AddNew(elem.Name, "Requirement")
This works. Neverless the real problem I got is that I want to delete the element in t_objectrequires. With
"DELETE FROM t_objectrequires WHERE..." it is not possible.
Does anybody has an idea how this works?
Or exists already a function "move all requirements to external"?

Thanks in advance

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add-In, C#, MOVE External
« Reply #1 on: September 30, 2011, 09:55:58 pm »
Caroline,

In order to delete an element you  have to delete it from it's parent collection.
So in order to delete the requirements you have to do ownerElement.Requirements.DeleteAt(index)
So I think you better get "real" elements that have an internal requiremenent with your sql query and then loop over them to get to the requirements.

Geert

PS. If you want to execute update queries against the database you'll have to use the undocument operation Repository.Execute(sqlUpdateString)

carolin.boeckler

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Re: Add-In, C#, MOVE External
« Reply #2 on: September 30, 2011, 10:10:48 pm »
Hello Geert,

It's awesome

Thanks it works

How did you know about the function Repository.Execute?

Caro

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add-In, C#, MOVE External
« Reply #3 on: September 30, 2011, 10:45:49 pm »
I think the same way you now know about that function ;)

Geert