How to Get the Lock of a Case
About Case Locking Strategies
Pega offers two primary case locking strategies to manage concurrent access:
1.Pessimistic Locking (Allow one user) - Only one user can access and edit a case at a time. Other users cannot update the case until it's unlocked or the lock expires.
2.Optimistic Locking (Allow multiple users) - Multiple users can work on the same case simultaneously. When changes are made, users receive notifications about updates from other users.
Implementing Programmatic Case Lock Checking
When you don't have the lock but need to perform actions on a case, follow these steps to implement a programmatic check for case locking:
1 - Create a Activity
- Create an Activity called 'GetLockObject' on your work class (in my case 'HTP-HowToPega-Work-SampleCaseType').
2 - Configure Your Pages and Classes
- Add your 'pyWorkPage' in pages and classes referencing your work class ('HTP-HowToPega-Work-SampleCaseType')
3 - Configure your activity
There is only one main step in the implementation process:
- Use the method 'Obj-Refresh-And-Lock' to ensure that a step page's contents are current and that an object is locked
- Set the 'pyWorkPage' page to the 'Step Page'
- Set the When condition to check if the page is locked:
- When: @isPageLocked(tools,myStepPage)
- if true: Exit Activity
- if false: Continue Whens
This implementation ensures that your application properly handles case locking scenarios, preventing data conflicts when multiple users attempt to access the same case.
References:
- https://docs.pega.com/bundle/dx-api/page/platform/dx-api/supported-feat…
- https://docs.pega.com/bundle/platform-241/page/platform/case-management…