I have vbscript, which creates new class (with stereotype "table") in EA. The script adds attributes and its datatypes to the class - till this point the script works OK.
The problem is to add a primary key. To add primary key I am using sub AddPrimaryKey (see bellow, table = the class into which PK should be added, name = name of the new PK (new atribute), datatype = datatype for PK, note = note for PK).
When I checked the created class in the Project browser-> Class -> Table detail -> Columns/Attributes, the primary key checkbox is not checked.
Where is the problem? What should I do so that Primary key checkbox will be set?
sub AddPrimaryKey(table, name, datatype, note)
dim newattributes as EA.Collection
set newattributes = table.Attributes
dim newAttribute as EA.Attribute
set newAttribute = newattributes.AddNew( name, datatype )
newAttribute.Stereotype = "column"
newAttribute.AllowDuplicates = 1
newAttribute.Notes = note
newAttribute.Update()
newattributes.Refresh
dim newOperations as EA.Collection
set newOperations = table.Methods
dim newMethod as EA.Method
set newMethod = newOperations.AddNew("PK_"+Mid(table.Name,4),"")
newMethod.Stereotype="PK"
newMethod.Update
newOperations.Refresh
dim parameters as EA.Collection
set parameters = newMethod.Parameters
dim newParameter as EA.Parameter
set newParameter = parameters.AddNew( name, datatype )
newParameter.Update()
parameters.Refresh()
newMethod.Update
newOperations.Refresh
end sub