Author Topic: Updating tagged value is not working  (Read 9896 times)

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Updating tagged value is not working
« on: November 09, 2021, 10:37:41 pm »
I have a problem assigning new value to a tagged value and then read it back using C#.

Executing this code fragment, "taggedValueRead" contains the value before assigning the "new" value.
I tried Update() and Refresh() calls, nothing helped.
If the element after execution is unselected in the model and then selected again, the tagged value contains the value "new". Therefore, the tagged value is changed.

Dieter

Code: [Select]
EA.Element element = iEA.GetContextObject as EA.Element;
EA.TaggedValue taggedValue = element.TaggedValues.GetByName("MDG::name");
if (taggedValue != null)
{
    taggedValue.Value = "new";
    taggedValue.Update();  element.Update();  element.Refresh(); // just to be sure

    EA.TaggedValue taggedValueRead = element.TaggedValues.GetByName("MDG::name");
    if (taggedValueRead != null)
    {
        iEA.TabWrite("value: " + taggedValueRead.Value); // -> outputs the old value
     }
}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating tagged value is not working
« Reply #1 on: November 10, 2021, 12:00:57 am »
Try
Code: [Select]
element.TaggedValues.Refresh()
This will reload the tagged values collection from the database.

Geert

PS. I never use TaggedValues.GetByname as I'm never certain there aren't going to be two tagged values with the same name.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: Updating tagged value is not working
« Reply #2 on: November 10, 2021, 08:50:59 am »
GetByName doesn't work on the qualified name of the tag, so unless you've actually set that as the name of the tag it will never return anything.

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Re: Updating tagged value is not working
« Reply #3 on: November 11, 2021, 12:50:24 am »
Hi Geert,
thanks - it works.

Hi Eve,
GetByName() works for me with qualified tag names.
What is the better method than TaggedValues.GetByname()?

Dieter

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating tagged value is not working
« Reply #4 on: November 11, 2021, 01:06:08 am »
What is the better method than TaggedValues.GetByname()?
Loop over the TaggedValues collection and check the name.

Something like

Code: [Select]
        For Each existingTag In element.TaggedValues
            If existingTag.name = "CR" Then
Set taggedValue = existingTag
Exit For
end if
        Next
In this case you are in control of what happens when you have multiple tagged values with the same name.

Geert