function preProcessor(q, field, document, userId, logger) { 
    //logger.info("------TESTING DATE PREPROCESSOR");
    let moment = require('moment');
    
    if (document[field.name] && Array.isArray(document[field.name]) ) {
        let saveValue = document[field.name];
        //**************************************
        let isInValid = false;
        for(let i = 0; i < document[field.name].length; i++){
            if(document[field.name][i].createdDate) {
                let date = moment(document[field.name][i].createdDate, ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
                if (date.isValid()) {
                    document[field.name][i].createdDate = date.toDate();
                } else {
                    isInValid = true;
                    break;
                }
            }
            if(document[field.name][i].modifiedDate) {
                let date = moment(document[field.name][i].modifiedDate, ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
                if (date.isValid()) {
                    document[field.name][i].modifiedDate = date.toDate();
                } else {
                    isInValid = true;
                    break;
                }
            }
            if(document[field.name][i].comments && Array.isArray(document[field.name][i].comments)){
                for(let j = 0; j < document[field.name][i].comments.length; j++){
                    if(document[field.name][i].comments[j].createdDate){
                        let dateComment = moment(document[field.name][i].comments[j].createdDate, ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
                        if (dateComment.isValid()) {
                            document[field.name][i].comments[j].createdDate = dateComment.toDate();
                        } else {
                            isInValid = true;
                            break;
                        }
                    }
                }
            }
            if(document[field.name][i].notesHistory && Array.isArray(document[field.name][i].notesHistory)){
                for(let j = 0; j < document[field.name][i].notesHistory.length; j++){
                    if(document[field.name][i].notesHistory[j].createdDate){
                        let dateComment = moment(document[field.name][i].notesHistory[j].createdDate, ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
                        if (dateComment.isValid()) {
                            document[field.name][i].notesHistory[j].createdDate = dateComment.toDate();
                        } else {
                            isInValid = true;
                            break;
                        }
                    }
                    if(document[field.name][i].notesHistory[j].modifiedDate){
                        let dateComment = moment(document[field.name][i].notesHistory[j].modifiedDate, ["DD/MM/YYYY hh:mm a", "DD/MM/YYYY", "hh:mm a","DD/MM/YY","DD/MM/YY hh:mm a","DD/MM",moment.ISO_8601], true);
                        if (dateComment.isValid()) {
                            document[field.name][i].notesHistory[j].modifiedDate = dateComment.toDate();
                        } else {
                            isInValid = true;
                            break;
                        }
                    }
                }
            }
            if(isInValid){ break; }
        }
        if(isInValid) {
            let errMsg = field.componentName + " field named " + field.name +
                    " has invalid value \"" + saveValue + "\"";
            logger.error("Preprocessing Failure : " + errMsg);
            return null;
        }
    } else {
        return document;
    }
}
module.exports = preProcessor;
