Author Topic: Javascript issue - newly added method not found in subsequent call to GetByName  (Read 861 times)

Thomas Arnbjerg

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 12846
  • Karma: +535/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
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