@AndrewW16838926 as per the suggestion in the closed support ticket, please engage with consulting team to provide more information on the design change.
If you have resolved it, please post your solution here in a reply and mark it as accepted solution. If you still need help, see below:
This is a GenAI-powered tool. All generated answers require validation against the provided references.
You are writing about a race condition issue with the “Auto Get” button in your Pega implementation.
I understand that when multiple users click this button simultaneously, the same case is being assigned to different users, even though it should only be assigned to one user. This is a classic race condition problem that occurs when concurrent operations try to access and modify the same resource.
Based on your description, I’ve identified several approaches to solve this issue:
1. Implement Optimistic Locking with Status Tracking
The most effective solution would be to modify your data transform to implement a status tracking mechanism with optimistic locking:
- Add a new property to your case class (e.g.,
pyAssignmentStatus) that can have values like “Available”, “InProgress”, or “Completed”.
- Modify your data transform to:
- First check if the case status is “Available” before attempting to assign it
- Immediately update the status to “InProgress” when a case is fetched
- Include this status check and update in a single transaction to prevent race conditions
Here’s a conceptual approach for your data transform:
// Step 1: Query for available cases with a WHERE condition that filters for "Available" status
SELECT * FROM YourCaseClass WHERE pyStatusWork != "Resolved-Completed" AND pyAssignmentStatus = "Available" ORDER BY pxCreateDateTime ASC
// Step 2: In the same transaction, update the status of the selected case
obj.pyAssignmentStatus = "InProgress"
obj.pyAssignedTo = UserIdentifier
obj.Update()
2. Use Pega’s Built-in Locking Mechanism
Configure your case type to use the “Allow one user” locking strategy:
- Navigate to App Studio > Case Types > [Your Case Type] > Settings > Locking
- Select “Allow one user” in the “Access strategy to open and work on a Case” section
- Set an appropriate timeout value (default is 30 minutes)
This will ensure that when one user accesses a case, it’s locked for other users until the lock is released or times out.
3. Implement a Synchronized Activity
Replace your current data transform with an activity that uses synchronized Java code:
- Create a new activity that will handle the case assignment
- Use the
synchronized keyword in Java to ensure that only one thread can execute the critical section at a time
- Within this synchronized block, fetch and assign the case
Example Java code in an activity:
synchronized(this.getClass()) {
// Fetch the oldest available case
String caseID = tools.findPage("YourDataPage").get("CaseID");
// Check if case is already assigned
if (caseID != null && !isAssigned(caseID)) {
// Mark as assigned
markAsAssigned(caseID, tools.getAuthenticatedUserName());
return caseID;
} else {
// Return null or handle the case where no cases are available
return null;
}
}
4. Database-Level Locking
If your database supports it, you can use database-level locking mechanisms:
- Modify your SQL query in the data transform to use
SELECT FOR UPDATE which locks the selected rows
- This prevents other transactions from modifying these rows until your transaction is complete
Example SQL:
SELECT * FROM YourCaseClass WHERE pyStatusWork != "Resolved-Completed" ORDER BY pxCreateDateTime ASC LIMIT 1 FOR UPDATE
Recommended Approach
Based on your specific scenario, I recommend implementing the first approach (Optimistic Locking with Status Tracking) as it provides the most robust solution while maintaining good performance. This approach:
- Adds a status field to track assignment state
- Updates this status atomically when assigning cases
- Prevents the same case from being assigned to multiple users
- Handles race conditions gracefully without requiring heavy locking
This solution addresses the core issue where the data transform is returning the same case ID to multiple users when they click the “Auto Get” button simultaneously.
References:
If this answered your question, please click ‘Accept Solution’