This example shows how the Designer Studio can be used to view case type instances and how an Activity can be used to delete case type instances from the PRPC database in Pega 7. The activities in this tutorial will use the Obj-Delete-By-Handle and Obj-Browse methods to either delete single instances or multiple instances. Note that case type instances should not be deleted this way in a production environment. Please refer to the Purge and Archive Wizards for information on how to delete and archive old work on production systems.
- How to Delete a Class (e.g. Case Type Rule) and All of its Rules in Pega 7
- How to Delete a RuleSet in Pega 7
- Example of Connecting to Pega 7.1.6 PRPC PostgreSQL DB with pgAdmin
- View Instances of Case Type Rule in the Pega 7 Designer Studio or DB Tool such as pgAdmin
- Delete a Single Case Type Instance by Handle with Obj-Delete-By-Handle
- Delete Multiple Case Type Instances with Obj-Browse and Obj-Delete-By-Handle
For this example, a case type called
Auto has been created to capture the processes needed for providing auto insurance quotes to customers. The
Auto case consists of 3 stages as shown in the screen shot below. Customer and vehicle information is collected and used to calculate an auto insurance quote. When running the case type rule, new instances are created and stored in the PRPC database.
The Designer Studio can be used to view all instances of a given case type rule. Navigate to the Application Explorer and right click on the case type rule. In the context menu, hover over View and click on Instances as shown in the screen shot below.
A list type report will execute and show all instances of the case type rule. In this example, there are 44 instances of the
ABC-Insurance-Work-Auto case type rule. The list report shows the unique instance names, when the instances where last updated and by what operator. In the below example, the instance names are
A-4 and so on. An instance name is automatically generated by PRPC when a new case type instance is created.
It is also possible to use an external database client to view the case type instances. In this case, PRPC is using PostgreSQL for the database. For detailed instructions on how to use the pgAdmin client for connecting to and viewing the PRPC database, please refer to this blog post. The pgAdmin client can be used to look at the
Auto case type instances stored in a database table in the PegaDATA schema.
In order to identify the table name, open the Auto class in the Designer Studio by navigating to the Application Explorer and expanding the case type rule. Next, expand the SysAdmin item and then expand the Class item and click on the actual class name of the case type rule to open the Edit Class form. Here, the class name is
ABC-Insurance-Work-Auto and the class group name is
On the Edit Class form, scroll down and click on the button Test Connection. A new dialog will pop up and show the actual table name in the PegaDATA schema. In this case, since the class belongs to a class group, the instances are stored in a table for the class group class. In this example, the table name is:
The external DB tool, such as pgAdmin in this example, can be used to navigate the PegaDATA schema schema and open the
pc_ABC_Insurance_Work table to view the case type instances.
In pgAdmin, right clicking on a table name allows to view the rows in that table. The below screen shot shows the instances of
An activity can be used to delete a single case type instance by its handle. To create a new activity for this purpose, right click on the case type rule in the Application Explorer and hover over +Create and then Technical and click on Activity.
The Create Activity form will be loaded. Enter a meaningful label and leave the Apply to class so that it matches the case type rule for which instances should be deleted. Select a ruleset and click on the Create and open button.
Parameters tab: On the Edit Activity form, navigate to the Parameters tab and add a mandatory input parameter
instanceHandle (i.e. ID) that will hold an instance handle and then click on Save.
Steps tab: On the Steps tab, add a step that calls the method Obj-Delete-By-Handle. Expand the method and set the InstanceHandle method parameter by referring to the input parameter created earlier. Also check the checkboxes Lock, ReleaseOnCommit and Immediate to obtain a lock for the instance that is to be deleted and to commit the database operation immediately.
Security tab: On the Security tab, check the option Allow direct invocation from the client or a service so that the activity can be run directly in the Designer Studio.
Save the activity and unit test it by clicking on Actions > Run. Enter the instance handle on the test page. The instance handle is a string composed of the class group name and the instance name. Note that the
Auto class belongs to class group
For example, the instance handle for the Auto case type instance with the name
ABC-Insurance-Work A2. Click on Execute to run the activity.
A confirmation message will indicate that the activity executed successfully. Use the methods described earlier to view the instances of the
Auto case type rules and confirm that the instance has been deleted from the database.
Instead of deleting a single case type instance by handle, multiple instances can be deleted as well. In this example, all instances that have not been updated since a given data time are deleted. The below screenshot shows the instances again, ordered in descending order by UPDATED ON property. There are a total of 43 instances.
The activity should delete all instances that have not been updated since 9:00 AM May 5th, 2016. In the below example, 27 instances would be deleted because the UPDATED ON property of the top 16 instances is greater than 9:00 AM May 5th, 2016.
Create a new Activityin the same way as before:
Give the new activity an appropriate label:
Click on Create and open and navigate to the Pages and Classes tab and add a page of type Code-Pega-List. Here, the page name is
Security tab: As before, check the option Allow direct invocation from the client or a service so that the activity can be unit tested. Save the changes and navigate to the Steps tab.
Steps tab: On the Steps tab, add a step that calls the Obj-Browse method and in the PageName field, enter the name of the
Code-Pega-List page defined on Pages and Classes, in this case it is
AutoCaseList. Also set the name of the class in the ObjClass field, here it is
- The Obj-Browse method allows to set filter criteria. Here, we want to retrieve all instances where the UPDATED ON date is less than 9:00 AM May 5th, 2016.
- The corresponding property is called
pxUpdateDateTime. The condition is set to Is Less Than and the value is a DateTime string of the format
- According to that pattern the string for 9:00 AM May 5th, 2016 is
- Save the activity and trace its execution by clicking on Actions > Trace and then run it by clicking on Actions > Run.
- In this example, the Tracer will show 27 instances that match the Obj-Browse query with the filter on the last updated date.
- In order to delete these instances, add a loop step in the activity as shown below.
- When clicking on the Loop button in a step, a dialog pops up.
- Select For Each Embedded Page in the Repeat drop down and specify the class of the items in the page list, in this case it is
- Set the method to Obj-Delete-By-Handle and the step page to the page that holds the results of the Obj-Browse method and refer to pxResults, which is a list of the actual case type instances.
- In this case, the step page for the iteration is
AutoCaseList.pxResults. Check the method parameters Lock, ReleaseOnCommit and Immediate.
- Most importantly, set the InstanceHandle dynamically using the
pzInsKeyvalue of each instance item.
- Save the changes and run the activity by clicking on Actions > Run and then on Execute on the activity test page.
- A confirmation message will indicate that the activity was executed successfully, but returned no data.
- Use the Designer Studio to view the instances again. In this case, 27 out of the original 43 instances have been deleted and only 16 instances remain in the PRPC database.
Please register and leave comments or suggestions on how to improve this example!