Discussion
Pegasystems Inc.
JP
Last activity: 10 Mar 2024 6:06 EDT
How to update or delete a record in Table
Hi,
Let's say, you have a list of master data in a Table layout and you want to update some of the attributes in a record directly from the list (see below screenshot). Inline edit mode gives you the functionality to do so on UI, but it only updates data on memory, and it doesn't persist to the database by itself. I've seen many developers create their own activity to manually save the changes in the database looping over the list. That is fine, but in this post I am sharing a little easier approach to do this. Be noted, in this example I will demonstrate it using Data Type but this method can be applied to any concrete class (Data-, Work-, or others).
- Record update
1. Define a Data Type. Then create a Report Definition or Data Page to retrieve all records from the database and configure a Table that sources it.
2. In Operations tab, enable Inline Edit mode.
3. In Advanced section, turn on the following checkboxes and fill in the out-of-the-box activities.
1 | Run activity before grid update | pzPreUpdateRecordWrapper |
2 | Run activity after grid update | pzPostUpdateRecordWrapper |
4. That's it. Now double click on any record in a Table and update some attributes. Click outside of the Table and system immediately saves the changes in the database for you. It adds a record in the history table as well.
- Record delete
1. Add one more column in the Table and configure a Delete item icon.
2. For On-click event, add two actions - Delete Item and Refresh-This section.
3. You may expect that it should be working by now, but unfortunately it isn't. The reason for this is because, the out-of-the-box activity "pzPreUpdateRecordWrapper" step 2 is skipped. When condition is checking if the section name is "pzRecordEditor" or not.
4. So I did Save As this activity and named it "PreUpdateRecordWrapper". Remove above When condition (2nd row). Keep the class as @baseclass so you can reuse it for any class (Work-, Data-, and others).
5. Specify this new activity for "Run activity before grid update" as below.
6. That's it. Now you can test it.
- Notes
If the class has other dependent classes and you want to delete them in sync, you will have to manually clean them up. For example, if the list of Table is sourced in Link-Attachment class, Delete icon will only delete a record in Link-Attachment class and system won't delete Data-WorkAttach-File class or Repository.
Thanks,