Book a Demo

Author Topic: Programatically adding lists to a TaggedValue  (Read 4910 times)

njf

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Programatically adding lists to a TaggedValue
« on: November 14, 2013, 10:54:18 am »
I have created a stereotype for an operation called 'AtomicAction' within a profile (which has been imported as an MDG technology) which contains a TaggedValue called 'List of UDETs' which contains a list of elements of another defined stereotype, 'UDET', that I had created.

When I create a new method with the 'AtomicAction' stereotype via the EA GUI, all the TaggedValues are automatically added into operation. For the 'List of UDETs' TaggedValue I can browse and multi-select a set of UDET stereotyped elements.

But if I can't find a similar way to do this via the automation API. Firstly I create the method as follows:

op = nc.Methods.AddNew(aa1.Key(), "AA-Response")
currentMethods.Add(aa1.Key(), op)
op.Stereotype = "AtomicAction"
op.Update()


The TaggedValues are not automatically added into the method. I can add them via code, but they do not automatically appear as they do through the GUI. Is there a way to do that via the API?

Secondly, how do I add a list of elements into a Tagged Value via the automation API. It looked like it was just holding a comma delimited list of GUIDs within the TaggedValue.value so I constructed a string with the list of GUIDs as follows:

If udetGuids.Count > 0 Then
                Dim stringOfGuids As String = ""
                For Each guid As String In udetGuids
                    stringOfGuids += guid + ","
                Next
                ' remove last comma
                stringOfGuids = stringOfGuids.Substring(0, stringOfGuids.Length - 1)
                Dim mt As MethodTag
                Try
                    mt = op.TaggedValues.GetByName("List of UDETs")
                Catch ex As Exception
                    mt = op.TaggedValues.AddNew("List of UDETs", "TaggedValue")

                End Try

                If mt Is Nothing Then
                    mt = op.TaggedValues.AddNew("List of UDETs", "TaggedValue")
                End If

                If stringOfGuids.Length <= 255 Then
                    mt.Value = stringOfGuids
                Else
                    mt.Value = "<memo>"
                    mt.Notes = stringOfGuids
                End If
                mt.Update()
                op.TaggedValues.Refresh()


            End If


The value looks identical to the ones constructed via the GUI, but it doesn't then allow me to browse for the elements from the TaggedValue within the GUI - it is just text in the TaggedValue value field. I assume I have to somehow set the TaggedValue to be of a type list of 'UDETs' in the code.

Is there any simple solutions to these problems?

Thanks,
njf

njf

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #1 on: November 14, 2013, 01:29:33 pm »
Just an update, I changed to code to include the profile prefix on the stereotypes. This didn't have any impact on the 'AtomicAction' stereotype but when I add a TaggedValue name with the with the profile prefix, the tagged value type became a list of UDETs. But now I don't know how I add an element to this list via the automation API. The current implementation does not seem to apply anything to the value of the taggedValue any longer.

Slowly getting there....

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #2 on: November 14, 2013, 09:50:54 pm »
Which EA version do you use?

q.

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #3 on: November 15, 2013, 12:47:18 am »
Not exactly sure I fully understand issue, however what I do after having added the taggedvalue after:

mt.Update()
op.TaggedValues.Refresh()

is to update the owner of the TV collection and refresh

op.Update
op.Refresh

As I understand it this will ensure stuff gets stored in the database rather than just sitting around in memory and never getting store.


Should probably check the return status of the mt.Update and op.Update and act as appropriate.

« Last Edit: November 15, 2013, 12:48:39 am by MrWappy »
EXploringEA - information, utilities and addins

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #4 on: November 15, 2013, 07:55:45 am »
The Update actually stores the object in the database. The Refresh is only needed if you want to iterate the collection. Else it is not needed.

Regarding synch of TVs with MDG: pre 10.0? This has changed in the last version.

q.
« Last Edit: November 15, 2013, 07:57:35 am by qwerty »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #5 on: November 15, 2013, 07:16:36 pm »
@qwerty

I tend to always do the refresh (well nearly always) following updates as more often than not I will access the element collections again, and think its quicker, and safer, to refresh at point of update rather than have to do a refresh before accessing.  Good/bad habit - with EA I tend to over do!

BR


EXploringEA - information, utilities and addins

njf

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Programatically adding lists to a TaggedValue
« Reply #6 on: November 16, 2013, 06:40:23 pm »
I'm using version 10.0.1006 of EA.

Ok - I feel a bit foolish - the GUIDs I was adding into the list via the API were not the UDET elements GUIDs, but one of the GUIDs of its TaggedValues. Once I fixed this, everything started working as expected.

Thanks,
njf
« Last Edit: November 16, 2013, 07:25:44 pm by neilf75 »