Author Topic: Creating Template Binding automatically via JavaScript  (Read 3235 times)

AjithPadman

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Creating Template Binding automatically via JavaScript
« on: November 23, 2018, 01:53:25 am »
I would like to create Template binding connection and the corresponding parameter Substitution specification of a large set of Classes with the Java Script based EA automation. I am able to successfully create a connector using the Element.Connectors.Addnew(""."Templatebinding") api. But I am not able to add the Formal and Actual Parameters to the connector using any automation methods.  I found that there is a Templatebindings Collection on a connector class. But This seems to be marked Read only and not able to update this collection. Does anybody know there is a possibility to create the templateBinding objects with definition for the Formal and actual and add it to the TemplateBinding Connector?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Template Binding automatically via JavaScript
« Reply #1 on: November 23, 2018, 02:06:52 am »
To add stuff to EA.collections you have to use AddNew() (as you already did by adding a new connector)

I've never use TemplateBindings before, but if there's a collection then you should be able to add new elements to it.

Geert

AjithPadman

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating Template Binding automatically via JavaScript
« Reply #2 on: November 23, 2018, 02:17:38 am »
I did the below code
Code: [Select]
var connection = currentElement.Connectors.AddNew("TemplateBinding","TemplateBinding");
Session.Output(connection.Name);
connection.SupplierID = el.ElementID;
var tempbinding = connection.TemplateBindings.AddNew("TemplateBindings",el.ElementGUID);
tempbinding.FormalName = "ReturnType";
tempbinding.ActualName = "Test";
tempbinding.Update();
connection.TemplateBindings.Refresh();
connection.Update();
el.Update();
currentElement.Connectors.Refresh();
currentElement.Update();

But this code does not seems to update the parameters substitution. Also I see the templatebinding Collection marked readOnly in the Connector Class Specification.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Creating Template Binding automatically via JavaScript
« Reply #3 on: November 23, 2018, 02:33:58 am »
Just as a guess. First create the connector and update it.

Code: [Select]
var connection = currentElement.Connectors.AddNew("TemplateBinding","TemplateBinding");
Session.Output(connection.Name);
connection.SupplierID = el.ElementID;
connection.Update();

Then do the other stuff with adding the tempBinding.

q.

AjithPadman

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating Template Binding automatically via JavaScript
« Reply #4 on: November 23, 2018, 04:25:47 am »
 :)Thanks a lot that worked well

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Template Binding automatically via JavaScript
« Reply #5 on: November 23, 2018, 04:54:17 am »
Also I see the templatebinding Collection marked readOnly in the Connector Class Specification.
All EA.Collections in the API are marked readonly.
That only means that you cannot set it

something like
Code: [Select]
thisElement.Attributes = otherElement.Attributes;Is not allowed (and will return a compiler error depending on the language used)

Geert