Audit log issue in before save hook

Hello Everyone 

I am facing an issue with the audit log in before save hook. 

I have a field that is enabled for the audit log. In before save logic hook I am throwing an exception on specific conditions in which data is not getting saved but still audit log is getting created so I have to avoid this audit log being created when the data is not saved. 

I have checked that no other code is affecting this in other logic hooks and record.js files.

Thanks in advance

Parents
  • Hello

    Thanks for reaching out. 
    Regarding your scenario, is this Save action coming from the user interface? 


    If yes, the best approach would be to have any validation performed at the controller level, therefore, preventing the Save to be triggered at all if the conditions don't fit your requirements.

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Cookbook/Adding_Field_Validation_to_the_Record_View/index.html

    This will also prevent this validation to be triggered when the record is updated via other sources, Scheduler, API, related record saves (Etc..). That could cause Exceptions to be thrown that could impact non-related processes. 

    Let me know if this helps or if your scenario does not fit my recommendations. 

    Cheers, 

    André

  • Hello Andre,

    To prevent the creation of an audit log entry in logic hooks, a specific exception-based solution is sought to restrict users from changing the status of a lead within a certain time frame. When the status is set to "New lead," an exception is thrown to halt the status change for 4 hours. The exception successfully prevents users from modifying the status, but the problem lies in the creation of audit logs even when the data is not saved.

    To clarify, the desired behavior is to avoid recording any audit log when the exception is triggered and the status change is not allowed. Currently, the exception prevents the status change but does not prevent the audit log from being generated, even though the data remains unchanged.

    The objective is to find a solution that allows the exception to take precedence over the audit log creation when the status change is blocked. This way, users cannot change the status during the restricted period, and no audit log is recorded for the prevented change.

    Thanks

Reply
  • Hello Andre,

    To prevent the creation of an audit log entry in logic hooks, a specific exception-based solution is sought to restrict users from changing the status of a lead within a certain time frame. When the status is set to "New lead," an exception is thrown to halt the status change for 4 hours. The exception successfully prevents users from modifying the status, but the problem lies in the creation of audit logs even when the data is not saved.

    To clarify, the desired behavior is to avoid recording any audit log when the exception is triggered and the status change is not allowed. Currently, the exception prevents the status change but does not prevent the audit log from being generated, even though the data remains unchanged.

    The objective is to find a solution that allows the exception to take precedence over the audit log creation when the status change is blocked. This way, users cannot change the status during the restricted period, and no audit log is recorded for the prevented change.

    Thanks

Children
No Data