Book a Demo

Author Topic: Automated requirements import  (Read 4882 times)

chris pearce

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Automated requirements import
« on: October 18, 2014, 12:27:50 am »
I am wanting to import requirements from another tool from XML into EA using an standalone automation script I have come up with the following which looks like it should work but the eap file doesn't show the added requirements in the specified package... However the items are added somewhere as i can read them out again.....(multiple versions of the same thing as ive run it lots of times)..

Code: [Select]
           EA.Repository repo = new EA.Repository();
            EA.Package package = null;
            repo.OpenFile(@"C:\Temp\project1.eap");

            package = repo.GetPackageByGuid("{735D3E44-8417-4601-93D5-B7F6630CA782}");


            for (int i = 0; i < 10; i++)
            {
                var new_item = package.Element.Requirements.AddNew("foo"+i.ToString(),"requirement");
                new_item.notes = "blah blah blah";
                new_item.update();
                package.Element.Requirements.Refresh();
            }

            foreach (dynamic req_items in package.Element.Requirements)
            {
                Console.WriteLine(req_items.name.ToString());
            }


            repo.SaveAllDiagrams();
            repo.Exit();

Is this method a non starter or should i persevere or should i find an alternative..  I found a few threads on this but not much in terms of automation....
Ultimately i want to check for existing items  / avoid duplicates update existing etc in a daily batch.

Any help much appreciated....

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Automated requirements import
« Reply #1 on: October 18, 2014, 01:54:02 am »
Hi,

It could be that whenever you use the AddNew method the arguments should Name and Type (as you have), but the type should be a recognized type, sparx is case sensitive I think ? Try 'Requirement' as your type.

Also where in Sparx are you looking for your requirements - your code is adding them as requirements against the actual package element - you would view these by opening the Packages property sheet and viewing Rules->Requirements tab - I think ?

Regards,

Jon.
« Last Edit: October 18, 2014, 02:31:34 am by openit »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Automated requirements import
« Reply #2 on: October 18, 2014, 02:15:22 am »
You need to call package.Elements.AddNew ("name", "Requirement")

q.

chris pearce

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Automated requirements import
« Reply #3 on: October 18, 2014, 11:44:31 pm »
Top marks chaps right in both cases this :
Code: [Select]
           for (int i = 0; i < 10; i++)
            {
                var new_item = package.Elements.AddNew("foo"+i.ToString(),"Requirement");
                new_item.notes = "blah blah blah";
                new_item.update();
                package.Element.Requirements.Refresh();
            }
Does much more like i what I was expecting...  Thanks guys :)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Automated requirements import
« Reply #4 on: October 20, 2014, 08:55:55 am »
Quote
Code: [Select]
package.Element.Requirements.Refresh();
This won't do anything based on the other code in your sample.

(It will update the API collection of requirements against the package itself allowing subsequent API calls to access them, since you're no longer working with that collection it's unnecessary)