Book a Demo

Author Topic: How to update a tagged value of an element in a VB script ?  (Read 3107 times)

Domoina

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
How to update a tagged value of an element in a VB script ?
« on: February 28, 2019, 09:44:22 pm »
Hi,

I'm trying to update the tagged value of an element in a VB script like below :
(the tagged value is empty at the beginning)

Code: [Select]
        element.TaggedValues.GetByName("myTaggedValue").Value = "1"
element.TaggedValues.Refresh
        element.Update

But it doesn't work, the tagged value is still empty (even after the reload of the diagram).

So I tried with a SQL query :

Code: [Select]
        sqlUpdate="UPDATE t_objectproperties set Value= '1' where Object_ID = " & element.ElementID & " AND Property = 'myTaggedValue'"
Session.Output sqlUpdate
Repository.Execute(sqlUpdate)

But I get an error : DAO.Database [3144], syntax error in Update instruction.
What I get in the Output is :
Quote
UPDATE t_objectproperties set Value= '1' where Object_ID = 3161 AND Property = 'myTaggedValue'
I tested the query on a PostgreSQL database and it works well.

What I'm doing wrong ?

Thanks
« Last Edit: March 01, 2019, 12:20:06 am by Domoina »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to update a tagged value of an element in a VB script ?
« Reply #1 on: February 28, 2019, 10:47:23 pm »
You have to update() the tagged value, not the element.
Try this:

Code: [Select]
dim myTag as EA.TaggedValue
set  myTag = element.TaggedValues.GetByName("myTaggedValue")
myTag.Value = "1"
myTag.Update

Geert

Domoina

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to update a tagged value of an element in a VB script ?
« Reply #2 on: March 01, 2019, 12:19:02 am »
Works like a charm  :)

Thank you Geert