Issue
A custom Business Rules causes the error below:
Unique Key violation detected by database ((conn=905588) Duplicate entry 'cae8a2b3db360854580e61f74b96197c' for key 'PRIMARY')
02:46:19 AM.476 GlideSession message was modified by sanitization. [message=Unique Key violation detected by database ((conn=905588) Duplicate entry 'cae8a2b3db360854580e61f74b96197c' for key 'PRIMARY')][sanitized=Unique Key violation detected by database ((conn=905588) Duplicate entry 'cae8a2b3db360854580e61f74b96197c' for key 'PRIMARY')]
log02:46:19 AM.480 FAILED TRYING TO EXECUTE ON CONNECTION glide.21 (connpid=905588): INSERT INTO task .....
Cause
Business Rule contains ritm.update() andi s updating the RITM record itself when it is being created, so being the same situation as of current.update.
Resolution
As per best practices, avoid .update and current.update() in before business rules, to avoid recursive calls.
Prevent recursive business rules
Avoid using current.update() in a business rule script. The update() method triggers business rules to run on the same table for insert and update operations, leading to a business rule calling itself over and over. Changes made in before business rules are automatically saved when all before business rules are complete, and after business rules are best used for updating related, not current, objects. When a recursive business rule is detected, the system stops it and logs the error in the system log. However, current.update() causes system performance issues and is never necessary.
Related Links
See documentation for future reference: How business rules work