Book a Demo

Author Topic: Update tag value  (Read 7459 times)

Markus Rohner

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Update tag value
« on: February 08, 2018, 09:02:23 pm »
I want to update an existing tag value (eventDefinition) of an BPMN2.0::StartEvent.
First I tried it with adding an new tagged value to the event.
But I noticed, that the event already got that tag (eventDefinition = None) and I got two tagged values with the same name.
So I wrote code to loop through the tagged value and to set the desired value using SetAttribute (according to Enterprise Architect Object Model).

// Create a new element in the package
EA.Element scheduleEvent = collabModelElements.AddNew(JobStartEventName, "BPMN2.0::StartEvent");
scheduleEvent.Stereotype = "StartEvent";
                       
// Set Timer as TaggedValue
EA.Collection scheduleTags = scheduleEvent.TaggedValues;

// Search the tag collection
for (short i = 0; i < scheduleTags.Count; i++)
{
    EA.TaggedValue currentTag = scheduleTags.GetAt(i);

    // Update the tag
    if (currentTag.Name == "eventDefinition")
    {
        Console.WriteLine("&&&& FOUND Event Tag: " + currentTag.Name);
        currentTag.SetAttribute("eventDefinition", "Timer");
        currentTag.Update();
    }
}
scheduleTags.Refresh();

scheduleEvent.Update();
collabModel.Elements.Refresh();


The tagged value is found (I get that Console output), but the tagged value is still "None".
What am I doind wrong?`
Thanks.

Markus

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Update tag value
« Reply #1 on: February 08, 2018, 10:01:04 pm »
Try enabling 'Show Duplicate Tags' in Tagged Values window to make sure there isn't a hidden tag that you are writing too.

Markus Rohner

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Update tag value
« Reply #2 on: February 08, 2018, 10:31:13 pm »
'Show Duplicate Tags' is enabled. But there (Properties > Tags) are no tags visible.
I can see them all in the Element Browser.
And there I could see two tags with the same name, when I added the tag. One tag was still 'None' and the other had the value 'Timer'.

When I update the Event in EA (Properties > BPMN2.0 > Type --> Timer) the tagged value gets changed and the icon gets updated (circle with a clock).

Nabil

  • EA User
  • **
  • Posts: 149
  • Karma: +5/-2
    • View Profile
    • View My LinkedIn Profile Here
Re: Update tag value
« Reply #3 on: February 08, 2018, 10:52:10 pm »
I have used the below syntax for some of tag updates never had any issue

if tag.Name = "eventDefinition" then
tag.Value = "Link"
tag.Update
eaElem.TaggedValues.Refresh
End If

HTH

BR
Nabil
Nabil

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Update tag value
« Reply #4 on: February 08, 2018, 11:06:27 pm »
The problem is here:

Code: [Select]
currentTag.SetAttribute("eventDefinition", "Timer");
I'm not sure what the SetAttribute is used for structured tagged values (I've never used that). But I'm pretty sure you should just set the currentTag.Value, so
Code: [Select]
currentTag.Value = "Timer");
Also you don't need all those Refresh() calls. Why does everyone keep including those. You only need those if you add or remove an element from a collection. Refresh() will then make sure it contains the correct number of objects. I almost never use that.

Geert

Markus Rohner

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Update tag value
« Reply #5 on: February 09, 2018, 12:40:44 am »
Code: [Select]
currentTag.Value = "Timer");did the job.

Thank you Nabil and Geert

I'm using all these Refresh() because I'm quiet new to EA API progamming and learned from example code. Obviously I didn't know what this Refresh() is doing.
Thanks for this hint too.

Markus