Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Thomas Arnbjerg on January 18, 2023, 10:15:28 pm
-
Hi all,
When I'm debugging a javascript script containing the following fragment the variable 'traceElement' is reported as 'undefined' at the first line containing 'traceElement.'. Any suggestions?
..
if (currentRequirement.Type == "Requirement"){
Session.Output( "Found link between " + currentUseCase.Alias + " to " + currentRequirement.Alias );
var traceElement as EA.Element;
traceElement = tracePackage.Elements.AddNew( currentUseCase.Alias + " to " + currentRequirement.Alias, "");
traceElement.TaggedValues.AddNew("from", currentUseCase.Alias);
traceElement.TaggedValues.AddNew("to", currentRequirement.Alias);
traceElement.Update();
tracePackage.Elements.Refresh();
}
..
-
Hi all,
When I'm debugging a javascript script containing the following fragment the variable 'traceElement' is reported as 'undefined' at the first line containing 'traceElement.'. Any suggestions?
..
if (currentRequirement.Type == "Requirement"){
Session.Output( "Found link between " + currentUseCase.Alias + " to " + currentRequirement.Alias );
var traceElement as EA.Element;
traceElement = tracePackage.Elements.AddNew( currentUseCase.Alias + " to " + currentRequirement.Alias, "");
traceElement.TaggedValues.AddNew("from", currentUseCase.Alias);
traceElement.TaggedValues.AddNew("to", currentRequirement.Alias);
traceElement.Update();
tracePackage.Elements.Refresh();
}
..
Hi Thomas,
The first thing I'd do is to change the name to see if it was name related or structural.
Paolo
-
Thanks for the tip.
Changed the name to foobar - did not solve the problem. Also I tried to make the variable global (yikes) - also without solving the issue.
Also the variable does not appear under 'locals'
-
Did the addNew operation fail for some reason? (because you passed an empty string as the type)
It might have failed silently. IIRC there is a getlatestError thing somewhere in like Repository. It might help, but I'm not sure.
Geert
-
Modified the script as follows. 'lastError' is empty in both locations.
'newElem' (renamed variable) is now reported as undefined on the line after the second assignment to 'lastError'. 'newElem' still does not appear under 'locals'.
..
if (currentRequirement.Type == "Requirement"){
var newElem as EA.Element;
var lastError;
lastError = Repository.GetLastError();
Session.Output( "Found link between " + currentSre.Alias + " to " + currentRequirement.Alias );
newElem = tracePackage.Elements.AddNew( currentSre.Alias + " to " + currentRequirement.Alias, "");
lastError = Repository.GetLastError();
newElem.TaggedValues.AddNew("from", currentSre.Alias);
newElem.TaggedValues.AddNew("to", currentRequirement.Alias);
newElem.Update();
tracePackage.Elements.Refresh();
}
..
-
Try passing a type as second parameter to the AddNew operation. An empty string is not a valid type.
Geert
-
That did it! Thanks! Set the second parameter to 'Class'
-
I'm guessing your tags not working will be your next issue.
var newTag as EA.TaggedValue;
newTag = newElem.TaggedValues.AddNew("from", currentSre.Alias);
newTag.Update();
newTag = newElem.TaggedValues.AddNew("to", currentRequirement.Alias);
newTag.Update();