Author Topic: Add New Tagged Value to the Attribute  (Read 5434 times)

zalbina

  • EA User
  • **
  • Posts: 149
  • Karma: +0/-0
    • View Profile
Add New Tagged Value to the Attribute
« on: September 14, 2012, 01:11:19 am »
Hello,

I'm trying to add some tagged value to an attribute usind API and VBA, but doing this: att.TaggedValues.AddNew "bla","bla" does not work. Even no errors. Should I use SQL for it?

Thanks

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Add New Tagged Value to the Attribute
« Reply #1 on: September 14, 2012, 02:02:05 am »
I have this code for updating tagvalues:

Public Function addOrUpdateTaggedValue(myElement As EA.Element, tagName As String, tagValue As String) As EA.TaggedValue
    Dim currentTag As EA.TaggedValue

    'update all tagged values with the given name
    For Each currentTag In myElement.TaggedValues
        If currentTag.Name = tagName Then
            currentTag.Value = tagValue
            currentTag.Update
            Set addOrUpdateTaggedValue = currentTag
        End If
    Next
    'no tagged value found, so create it
    If addOrUpdateTaggedValue Is Nothing Then
        If Len(tagValue) > 256 Then
            Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "Memo")
        Else
            Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")
        End If
        
        addOrUpdateTaggedValue.Value = tagValue
        addOrUpdateTaggedValue.Update
    End If
End Function

Robert Sheridan

  • EA User
  • **
  • Posts: 105
  • Karma: +0/-0
    • View Profile
Re: Add New Tagged Value to the Attribute
« Reply #2 on: September 14, 2012, 02:52:07 am »
There were some earlier posts around this.  Can not remember what the gotcha was off hand but I think the tagged value for an attribute is in a different bit of the object hierarchy (and with a different name) to element tagged values. If you check the help it tells you.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add New Tagged Value to the Attribute
« Reply #3 on: September 14, 2012, 04:31:23 pm »
No you shouldn't need to resort to SQL.
The code posted by OpenIT Solutions should work just fine (seems somehow familiar  ;))

Geert

zalbina

  • EA User
  • **
  • Posts: 149
  • Karma: +0/-0
    • View Profile
Re: Add New Tagged Value to the Attribute
« Reply #4 on: September 19, 2012, 04:30:36 pm »
Thank you everyone for your replays :).

zalbina

  • EA User
  • **
  • Posts: 149
  • Karma: +0/-0
    • View Profile
Re: Add New Tagged Value to the Attribute
« Reply #5 on: September 19, 2012, 07:17:51 pm »
This is, actually wrong:

Set addOrUpdateTaggedValue = myElement.TaggedValues.AddNew(tagName, "String")

Because this function returns EA.TaggedValue and AddNew function returns type Object. So, type mismatch. Is it possible to convert from one type to another in VBA?

Thanks.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add New Tagged Value to the Attribute
« Reply #6 on: September 19, 2012, 07:37:02 pm »
Try changing EA.TaggedValue in EA.AttributeTag

Geert

zalbina

  • EA User
  • **
  • Posts: 149
  • Karma: +0/-0
    • View Profile
Re: Add New Tagged Value to the Attribute
« Reply #7 on: September 19, 2012, 08:28:28 pm »
Miracle. It does work when I've changed it to EA.AttributeTag.

Thanks a lot.