Monday, August 26, 2013

PowerDesigner: Generate automatic incrementing index name and code

Would you like to have index names and code generated with something other than Index_1, Index_2, etc.?

Here's how to do that. (Thanks for guidance from Robert Adlington, SAP/Sybase Technical Publications Manager).

  1. Open the XDB file (Oracle used in this case)
  2. Navigate to root:Profile\Index.
  3. Right click Index in the navigation column and select New->Event Handler.
  4. Select Initialize from the drop-down list
  5. In the Event Handler Script tab, enter your custom code:  I use:
    obj.SetNameAndCode obj.parent.name + " Index", Left(obj.parent.code, 24) + "_IDX"
After doing the above, in a table's property sheet on the Indexes tab, create a new index.  It should use the text from the table's Name attribute plus the word "Index" for the index's name and the first 24 characters of the table's Code attribute plus the _IDX extension for the index's code value.

The first index will have suffix _IDX and the second will have _IDX2, with the number incrementing for each additional index.  

The SetNameAndCode method applies any naming conventions and also verifies uniqueness - hence the incrementing suffix. I can’t make the first index end in 1, but you may be able to enhance the script to do so if it is important to you. [Rober Adlington]

If you use name to code conversions, the abbreviations from your conversion table will be picked up automatically in the index's code.  However, if you use a different abbreviation for Index than IDX, you will need to change the code entered into the Event Handler Script tab to use that instead.

Unfortunately, I don't know how to get the conversion table's abbreviations to be picked up automatically in that script (yet!)  If someone knows how to do that, please let all of us know with your added comment.

No comments:

Post a Comment