Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: MaXyM on September 28, 2018, 12:36:57 am
-
Hello.
Likely i'm performing some conceptual mistake... but cannot find the root cause.
Originally the need of writing the script comes from EA bug during database RE, resulting duplicating Tagged Values. See image:
(https://i.imgur.com/uQGmlak.png)
Script should copy value from uppercase TV to lowercase one, and then remove the first one from the object.
Here is the code:
function main()
{
var tbl as EA.Element;
tbl = GetElementByGuid('{7E0B2D3D-ABB8-4c3b-9B2B-A7A2B38A5CE0}');
NormalizeDoubledTV(tbl, 'Owner');
NormalizeDoubledTV(tbl, 'Tablespace');
NormalizeDoubledTV(tbl, 'DBVersion');
}
function NormalizeDoubledTV(tbl, tvname)
{
var lwr as EA.TaggedValue;
var upr as EA.TaggedValue;
lwr = tbl.TaggedValues.GetByName(tvname);
upr = tbl.TaggedValues.GetByName(tvname.toUpperCase());
if (lwr !== null && upr !== null)
{
lwr.Value = upr.Value;
lwr.Value = upr.Value;
tbl.TaggedValues.Refresh();
tbl.Update();
DeleteTaggedValue(tbl, tvname.toUpperCase());
}
}
function DeleteTaggedValue(objj, tvname)
{
var obj as EA.Element;
obj = objj;
for (i = 0; i<= obj.TaggedValues.Count; i++)
{
var currentTagVal as EA.TaggedValue;
currentTagVal = obj.TaggedValues.GetAt(i)
if (currentTagVal.Name == tvname)
{
obj.TaggedValues.DeleteAt(i, false);
obj.Update();
obj.TaggedValues.Refresh();
return;
}
}
}
I debugged the issue down to the point, that I know the value of lowercased TV is updated until entering for loop in DeleteTaggedValue. So currentTagVal variable contains not updated value. I was sure that in javascript references to objects (variables) are being passed.
thanx in advance
-
You should not use GetByName with TVs since they are ambiguous. Use your own operation to iterate the collection.
q.
-
I'm pretty sure GetByName is case insensitive, and returns the first (without a defined order) instance it finds.
I too never use that operation.
Geert
-
OK guys, thanx for notes. The problem did lay between a keyboard and a chair ;)
There was lwr.Update() missing in NormalizeDoubledTV() function.
In addition to this, tbl.Update() is also not needed. tbl.TaggedValues.Refresh() is enough
Sorry for that, I really thought I explored all possibilities before posting the question.