Macro to Set Primary KeyAttributes

 I need a macro to set the the Prim,ary Key Attributes for an existing model and can't see how to do it:

  • The AttributeObj has a method to see if an attribute is a primary key - but this is read only
  • The Add method of the AttributeObj has a parameter to set the attribute to be a primary key on creation
  • I can't find it via an what to set is "primary key" for an existing attribute
  • I've looked at the Index methods IsPK and KeyType - but I can't  use these to set the Primary Key, at best I can create a unique index, but not primary key attributes

Can an existing attribute be set to a PK via a macro and if so how?

Regards,  Andrew

  • Hi, Andrew, our main macro expert is Stanley Chan, and he's on holiday this week. I'll follow up with him on Monday to get you an answer. Perhaps someone else in our community could provide some suggestions in the meantime. =)
  • Hi,

    Are you looking to set a specific column to be part of the Primary Key? If so then you should be able to just do the following:

    attributeObj.PrimaryKey = True
  • In reply to Stanley Chan:

    Hi Stanley - Thanks I've got it now :-) I've cribbed one of the import macros which in create/update on the entities/attributes and set the primary key

    The help text through me is states attributeObj.PrimaryKey is read only

    Regards, Andrew