How to create a relation between two tables via script - reloaded?

Some questions to the result of running the following script:
Relation = Model.AddLinkObject(2004, TenantEntity, Entity);
Relation.Name = RelationName;
Relation.Caption = RelationName;
Relation.Identifying = false;
Relation.MandatoryParent = false;
Attribute = Relation.ForeignKeys.GetObject(0).AttrChild;
Attribute.Name = AttributeName;
Attribute.Caption = AttributeName;
Attribute.Ordinal = 2;
Attribute.NotNull = false;
Pk = Entity.Keys.GetObjectByName(Prefix+’_PK’);
if (Pk == null) {
System.ShowMessageDialog(1000,‘AdaptEntitiesDialog’,‘Could not find PK ‘+Prefix+’_PK’,3,4);
else {
// Remove from Pk.KeyItems

  1. How to prevent the new attribute being added to the primary key?

  2. Or as workaround: How to remove an item from the KeyItems list?

3.Why is the new FK attribute always at the bottom and Attribute.Ordinal=2 ignored? How to move it up to the second position inthe script?

Thanx a lot.

Please help…
Are all people on holidays out there?


Hi Andreas,

See the reply at:

Thanks for your patience.


Vladka + TDM Team