cancel
Showing results for 
Search instead for 
Did you mean: 

Add columns to an existing key using scripting

Former Member
0 Kudos

I am new to PD scripting.  I would like to add a new column to an existing key within a table.  My code received an exeption message "Object creation can only be done through composition collections (Exception occurred.  0x80020009)."

Would someone post some sample code for me to plagarize?  If not for adding a column to a key, something similar.  (I have been successful in adding a new column to a table.)  Frankly I am clueless how to do it.  And I am having difficulty finding document for it.

Thanks for the help in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member200945
Contributor
0 Kudos

This is an example:

You have a table called Audit and it has a column called Retest Number.

Also this table has a key called Pk Audit

You want to add column Retest Number to key Pk Audit

'Find the column you want to add

set model=ActiveModel
set table = model.FindChildByName("Audit", Cls_Table)
Set Columns =table.Columns
for each c in Columns
  if c.name = "Retest Number" then
     set myCol = c
  end if
next

'Find the key and add the column
Set Keys = table.Keys
for each k in Keys
  if k.name = "Pk Audit" then
       set key_columns = k.columns
       key_columns.add(myCol)
  end if
next

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks Phillip.  It worked as you indicated.  If I may, where can I find documentation like this so that I do not have to post a question everytime I try to do something new?

Thanks again.