Author Topic: Trouble accesing collections of tagged values  (Read 4252 times)

Bex

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Trouble accesing collections of tagged values
« on: October 10, 2008, 10:44:04 pm »
Hi all,

My EA 7.1 add-in performs the following steps:

1) Create a new element in the repository
2) Set its stereotype (as defined in a pre-loaded profile, that is visible in the toolbox)
3) Synch the repository using the Repository.CustomCommand("Repository", "SynchProfile", "Profile=MyProfile;Stereotype=StereotypeName")
4) Attempt to get the TaggedValues collection from the element to set each tagged value's value
5) Update the element

The collection always returns empty but if I look at the newly created element (within EA) it has the tagged values as defined by the profile :-[

I have tried updating and refreshing the element prior to attempting to access the collection of tagged values, used both TaggedValues and TaggedValuesEx but the collection is always empty in my add-in yet they are visible in EA.........any ideas?

Thanks.


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #1 on: October 11, 2008, 12:45:46 am »
A guess: see if you can find the tagged values by searching for an 'owner' GUID in the stereotype table.
No, you can't have it!

Bex

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #2 on: October 11, 2008, 12:53:23 am »
Hi midnight,

I'll give that a try but I have the impression I'm missing something obvious. I read the thread regarding the "undocumented" SynchProfile custom command and it would appear that the poster was doing something similar to my add-in.

Thanks.    

Thomas H.

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #3 on: October 14, 2008, 07:34:49 pm »
Hello,

I had the same problem.

Then I iteraded over the tagged value collection and set the values I wanted to set and "updated" them immediately.

As a result: it is neccesary to update each tagged value instead of updating the tagged value collection.

Example:


Collection taggedValueCollection=newElement.GetTaggedValues();
short taggedValueCount=taggedValueCollection.GetCount();
TaggedValue currentTaggedValue=null;
            
String e_currentTagName;

for (short i=0; i<taggedValueCount; i++){
                  
      currentTaggedValue=(TaggedValue)taggedValueCollection.GetAt(i);
      e_currentTagName=currentTaggedValue.GetName();

      if (e_currentTagName.equalsIgnoreCase("MyTagValueName_01")) {
            setTaggedValueAndUpdate(currentTaggedValue, getMyTagValueName_01());
      }
      else if (e_currentTagName.equalsIgnoreCase("MyTagValueName_02")) {
            setTaggedValueAndUpdate(currentTaggedValue, getMyTagValueName_02());
      }  
      else if (e_currentTagName.equalsIgnoreCase("MyTagValueName_03")) {
            setTaggedValueAndUpdate(currentTaggedValue, getMyTagValueName_03);
      }  
}


private void setTaggedValueAndUpdate(TaggedValue u_taggedValue, String u_value){
      u_taggedValue.SetValue(u_value);
      u_taggedValue.Update();
}

private String getMyTagValueName_02() {
      return this. MyTagValueName_02;
}


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #4 on: October 14, 2008, 10:54:01 pm »
Thomas has voiced the important point here. You must Update() every item you create in EA. This must be done before attempting any call that uses the item in question, including a refresh of the containing collection. The Update() call actually causes the item to be saved to the underlying data store. Until then there is nothing for EA to manipulate.
No, you can't have it!

Bex

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #5 on: October 16, 2008, 04:05:54 am »
Hi,

Thanks for your replies. Maybe naively I thought that by applying a profile the tagged values would appear on the stereotyped element. I thought I could do something like:


EA.Element theReq = inPackage.Elements.AddNew("A Requirement", "Requirement") as EA.Element;
theReq.Stereotype = "Engineering";
string theResult = _Repository.CustomCommand("Repository", "SynchProfile", "Profile=MyProfile;Stereotype=Engineering");
          
theReq.Update();

EA.TaggedValue  theTV = theReq.TaggedValues.GetByName("myTaggedValue") as EA.TaggedValue;
theTV.Value = "Set to a value";
theTV.Update();

The problem is that theReq tagged values collection always has a count of zero....

I would like to create the tagged values this way so that they are not hard-coded but are defined by the profile.

Thanks,
Bex

Thomas H.

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #6 on: October 16, 2008, 09:50:07 am »
Hello Bex,

maybe the solution I am using is helpful for you as well:

1. Create the Element "Requirement" (as you did)
2. Apply the Profile to the newly created element once (as you did)
3. Update the element (I suppose you did)

Maybe new:
4. Apply again the profile
5. Update the element again


After applying the profile a second time and saving again the collection
    Collection taggedValueCollection=e_myNewElement.GetTaggedValues();
contained the values I expected, so that I could set them as described in my first answer.

Good Luck!

Tell me please if that helped.

Thomas

Bex

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Trouble accesing collections of tagged values
« Reply #7 on: October 22, 2008, 08:28:57 pm »
Hi Thomas,

Sorry for the delay in replying but your "2nd time lucky" approach worked!

So to summarise the steps:

1. Create the Element "Requirement"
2. Apply the Profile to the newly created element for the first time
3. Update the element
4. Apply the profile for a second time
5. Refresh the tagged values collection
6. Access and set each tagged value

Many thanks for your assistance :)