Book a Demo

Author Topic: TaggedValue created, but TaggedValues doesn't return it?  (Read 7624 times)

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
TaggedValue created, but TaggedValues doesn't return it?
« on: June 26, 2017, 07:39:58 pm »
This snippet checks to see if an element has a certain tagged value and creates it if it doesn't. It then checks to see the creation was successful but no matter what I do on readback activityScopeInCaseProjectTV is nothing even though the taggedvalue rewally has been created.

Code: [Select]
Session.output("Creating TV named " & asicpTvName & " for " & anEl.Name)
set activityScopeInCaseProjectTV = anEl.TaggedValues.AddNew(asicpTvName,"")
activityScopeInCaseProjectTV.Update
anEl.Update
anEl.Refresh
Repository.AdviseElementChange(anEl.ElementID)
set activityScopeInCaseProjectTV = anEl.TaggedValues.GetByName(asicpTvName)
if activityScopeInCaseProjectTV is nothing then
Session.output("TV named " & asicpTvName & " creation for " & anEl.Name & " failed")
end if
Why? How can I fix this it?

Thx,

Julian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #1 on: June 26, 2017, 08:14:27 pm »
I never use GetByName since it does not work on non-unique collections. Try a manual iteration over the elements and see what is returned.

q.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #2 on: June 26, 2017, 08:18:26 pm »
Can you clarify? What do you mean it doesn't work on non-unique collections?

(Iterate over the elements again? = make it even slower  :( )

PS If I count the element's tagged values immediately after creation that also returns zero so getAt also failed :(


Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #3 on: June 26, 2017, 08:37:17 pm »
Ok, iterating over the same collection again does allow getbyname to work.

But... has anyone collected a list of known issues of this type - the things that will catch out anyone other than an experienced EA scripter?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #4 on: June 26, 2017, 09:27:11 pm »
I once maintained a bug list publicly but then gave up since it just was growing and never really shrinking. Just get used to walk over mine fields. Use a stick to not get blast away directly.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #5 on: June 26, 2017, 11:19:44 pm »
As an experienced scripter, my advice is to not use GetByName in any situation.
And if you need to iterate a specific collection more then once store it in an ArrayList or Dictonary. That is usually ten times faster then iterating a native EA.Collection.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #6 on: June 27, 2017, 12:05:04 am »
Hi Julian,

In your code, you don't refresh Element.TaggedValues, which you need to do if you add objects to it. AdviseElementChange() is a GUI operation, it does not affect the objects in your code.

Other than that, what Geert said. You have to use Collections when manipulating various project content, but never ever create one yourself, and if you need to do a lot of back-and-forth, cache the contents in a better data structure.


/Uffe
My theories are always correct, just apply them to the right reality.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #7 on: June 27, 2017, 12:07:27 am »
OK! Thanks for the tips. In hindsight I think maybe element.taggedvaluesrefresh might have been necessary but I'm not doing that now :) Will certainly consider not using EA iterators too.

I don't suppose that old bug list is still around is it, just for curiosity's sake?

Julian

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #8 on: June 27, 2017, 12:08:41 am »
Uffe - my reply crossed with yours - thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #9 on: June 27, 2017, 01:02:33 am »
https://www.assembla.com/spaces/enterprise-architect/tickets

Also look at the "bug tracker" results from this site's search.

q.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: TaggedValue created, but TaggedValues doesn't return it?
« Reply #10 on: June 27, 2017, 07:28:59 pm »
Thanks qwerty.