Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Thomas Arnbjerg on June 06, 2023, 11:43:47 pm

Title: Javascript issue - newly added method not found in subsequent call to GetByName
Post by: Thomas Arnbjerg on June 06, 2023, 11:43:47 pm
I'm adding a method in Javascript like this:

function addSerialize(element){
      
   var signal as EA.Element;
   signal = element;
   
   var newMethod as EA.Method;
   newMethod = signal.Methods.AddNew("serialize", "void");    
   newMethod.Update();
   var newParameter as EA.Parameter;
   newParameter = newMethod.Parameters.AddNew("foobar", "int");
   newParameter.Update();
   newMethod.Parameters.Refresh();
   signal.Methods.Refresh();
        signal.Refresh();
}

After calling 'addSerialize(inputClass)' I try to retrieve serialize as:
var serializeFunction as EA.Method;
serializeFunction = inputClass.Methods.GetByName("serialize");

- but 'serializeFunction is undefined.

Any suggestions?
Title: Re: Javascript issue - newly added method not found in subsequent call to GetByName
Post by: Geert Bellekens on June 07, 2023, 01:23:51 am
Dont use getByName, but instead loop the collection and check for the name yourself.

GetByName only works on some collections, and even on those you can't predict which one (of the items with the same name) you get.

Geert