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 Reply Children
  • Hi 


    Thanks for the extra detail. 
    I still believe the best approach is to handle validation in a .js controller and prevent saving if conditions aren't met.

    I did a quick test locally and seems to work fine, do you think something like this would work for you? 

    custom/modules/Leads/clients/base/views/record/record.js

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    ({
    extendsFrom: 'LeadsRecordView',
    initialize: function (options) {
    this._super('initialize', [options]);
    // Add validation task
    this.model.addValidationTask('check_recycled_lead', _.bind(this._doValidateRecycledLead, this));
    },
    _doValidateRecycledLead: function(fields, errors, callback) {
    var leadStatus = this.model.get('status');
    var dateModified = new Date(this.model.get('date_modified'));
    var currentDateTime = new Date();
    // Calculate time difference in milliseconds
    var timeDifference = currentDateTime - dateModified;
    var hoursDifference = timeDifference / (1000 * 60 * 60);
    if (leadStatus === 'Recycled' && hoursDifference < 4) {
    errors['status'] = errors['status'] || {};
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX