Saturday, September 29, 2018

How to change key of class which already has intances

Context:

Let's assume that there is Employee class in Pega
Class Name: MyOrg-MyDiv-Data-Employee
Database Table: org_employee
Already there are 1000 records existing in the database table mapped to this class.
Now if we have requirement to add one more property as part of the class key. How can we do it ?

- We can delete all the records from database table, then Pega would allow to change the keys.
- Since deleting the records is not a good option, what is the alternative ?

Solution:

  • Open class rule definition. We could notice the existing keys.
  • Open Database Table instance rule corresponding to this rule. It will show org_employee.
  • Change it to pr_other. Go back to class rule definition, refresh it. It would allow us to add one more column as part of key. Save it. 
  • Then again navigate to Database Table instance rule and change the table back to org_employee. 
  • Once these changes are done. Go back to class definition and click on Test Connectivity.

Now we have added one more column as the key without removing any records from the table.
During deployment to higher environment, we need to send both the Class and Database table instance.


3 comments:

  1. Thank you so much for sharing your knowledge. You saved my day :D

    ReplyDelete
  2. I tried above steps, but getting below error while changing the table name to pr_other.
    'No classes should be explicitly mapped to pr_other table. This might lead to runtime errors as pr_other table might not have expected columns.'

    ReplyDelete
  3. How can we update newly added primary key for old 1000 records. I understand that , For new record 1001, it will be storing with new primary key only. but for existing records how this new primary key value will be stored

    ReplyDelete


HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu