Declare Index rule – tutorial
In this post, we will learn how to create and configure a declare index in Pega. It is highly recommended to visit my other blog article on declare index rule Understanding.
What are the different ways to create Declare index in Pega?
From the previous blog article, we already know that we can create Index tables for the embedded properties like page, pagelist and pagegroup. We also saw that embedded Pagegroup property ‘pyWorkParty’ is declaratively indexed.
In this article, we will see two examples. One with an Embedded page and the other with embedded pagelist examples.
There are two different ways to create Declare index
1. Automatic declare Index creation – This can be done via the Property optimization wizard when you need to optimize a property embedded in a pagelist property.
2. Manual declare Index creation – We can manually create all the declare index processing supporting rules and can be done for all the embedded properties like page, pagelist and pagegroup properties.
Business requirements
- DocumentsList – The documents are stored as list within the Mortgage request case as list pages. The columns like document name and Upload name should be exposed as separate Index columns and need to be used for reporting.
We will automate the declare index creation using the Property optimization wizard
- ValuationDetails – The valuation details are embedded within the Mortgage request case inside a page property – ValuationDetails. The columns ValuationAmount and ValuatorName should be exposed as separate Index columns and used for reporting.
For the second use case, we will be doing everything manually from our end.
Automatic Declare Index creation
We need to create Declare Index rules on the DocumentsList pagelist property.
Step 1: Start the Property Optimization wizard on DocumentsList property.
Open the App Explorer and expand the Datamodel properties.
Right-click on DocumentName or UploadDate embedded under the DocumentList property and click on ‘Optimize for reporting’
You should see the normal Property Optimization wizard.
Step 2: Complete the Property Optimization wizard.
From the highlighted text, we can clearly see Pega will be creating all the declare Index rules automatically from the wizard.
Complete the wizard.
You see it created different Declare index rules
Index class, Index property name, Declare Index rule and the tables and columns.
Step 3: Verify all the rules that are automatically created.
a. Index class – Index-MyOrg-Mortgage-Data-Documents
b. Index Property – Document Name
As we just exposed only a single property, it just did the same.
There is another property under the data class – UploadDate, which also needs to be exposed.
Let’s quickly optimize the other property as well using the same steps as above.
Make a note that it will not create another Index class or declare index rules 😊, It will just reuse or update the already created rules.
Now, you should see the UploadDate Index property created as well.
c. Declare Index rule – Index_DocumentsList
d. Database table instance – pr_Index_MyOrg_Mortgage_Data_D
e. Finally a dedicated table pr_Index_MyOrg_Mortgage_Data_D
You also see Pega uses all different OOTB columns to get populated on Index entries.
Step 4: Test the Declare Index entries.
Create a new case and capture the document name and Upload date under the Documents List.
As soon as you complete and save the step, you should see the declare index fires fom the tracer and also you should see new entries in the index tables.
Click Create and check the database table for M-3 case.
This works absolutely fine 😊
Manual Declare Index creation
Use case – ValuationDetails – The valuation details are embedded within the Mortgage request case inside a page property – ValuationDetails. The columns ValuationAmount and ValuatorName should be exposed as separate Index columns and used for reporting.
We will create all the rules manually for this use case. In real-time as well, you may need to manually create the declare index rules.
The reason is, that if you try to expose the property inside the embedded page property, it will always try to expose it directly in the work layer or the parent class layer by using external data mapping.
You can see from the above picture, the wizard is not trying to create Declare Index properties 😊
So when you want to create declare index for embedded page properties, you need to manually create all the necessary rules.
We already have the work and data properties ready to be exposed.
How do we start configuring Declare Index manually?
Step 1: Create an Index table.
Table name – index_myorg_mortgage_data_valrpt
Note: I am using Postgres SQL. I got the admin rights to create table. If there is a privilege restriction, kindly consult with DBA team to create a new Index table along with columns.
Don’t forget to include the main key columns and pzInskey
Tip: I just got the SQL query from another index table and just altered the necessary column names.
I have successfully created a new table. You can verify it below
Step 2: create a new index concrete class in Pega
Provide the required properties as keys.
Tip: You can Save-as already created Index class.
Keep a note that when you create any concrete class, Pega by default creates a dedicated table and the database table instance, you need to make sure to update it.
Step 3: Create the two properties in Index-address class.
Again, you can just Save-as the data class properties into Index class.
Step 4: Update the new Index database table instance
Note: As soon as you create a concrete class, pega will create a new DB table instance in pega and the database table. Make sure to drop the default table and we need to repoint to our newly created table
Update the table name to the newly created one –
Make sure to do the external mapping in the Index class rule form to make the connection with column names in the database table
Save the database table instance and then re-save the Index class record again, so that the database class mapping metadata will be updated correctly.
After re-saving, do the test connection from the class record.
Step 5: One final step, Create a new declare Index rule
Records -> SysAdmin -> Declare Index -> Create new
Complete the rule configuration with the right source and Index class specifications.
Properties for Indexing and mapping –
Set the source property from the address page in the left-hand side and Index property on right-hand side.
How simple is this? We have successfully configured declare index in Pega.
Let’s test it.
Step 1: Create a new case and capture the valuation details in the embedded page
Click Create to complete the transaction. This should automatically trigger the Declare index which should save an entry into Index table for M-4.
Step 2: Open the DB and verify the record in the Index table. ( M-4)
The valuator name and Valuation amount are set correctly!
Now let us test it differently.
Step 1: Create a test activity.
Step 2: In the first step – Open the M-4 work item
Step 3: In the second step – Property-set on Valuation details.
Step 4: In the last step – Obj-save with commit.
So what we are doing here? We are manually updating the valuation details. When we save the work item, the Index table should be updated with new values right? Let’s check it.
Step 5: Run the activity from the other actions button and trace it.
You should the Index step in the tracer
Step 6: Check the record in the index table. Pakka 😁
You can also try different DB operations like Deferred save (Obj-save without write now), delete option. You will understand that the Declare trigger fires only when the commit action is executed.
You can visit other declarative rules under this tag