//* PROPERTY OF BRANT PUTTKAMMER, PLEASE CONTACT ME IF YOU HAVE QUESTIONS //* PLEASE USE CAUTION WHEN RUNNING THIS PROGRAM ON YOUR SYSTEM console.clear(); let valueA = 0; let valueB = 0; let valueC = 0; let valueD = 99; var lenMyString = 0; let totalValue = 0; let imageModificationTime = null; let issueDate = null; let expirationDate = null; let lastVerificationDate = null; let category = null; let allErrorMessages = ''; CR.Script.fmMessageHandler = { // ASK CHRIS IF THE SCRIPT SHOULD RUN ONLY WHEN A FIELD CHANGE IS ONE OR WHEN THE PAGE IS LOADED? afterrender: function(fmMessage) { console.info('afterrender', fmMessage); ////alert(fmMessage.tableName); //can display validation for any existing errors console.info("hello friend ", fmMessage.query); console.info(fmMessage.event, fmMessage); console.info(fmMessage.columnName); //console.info("value " + fmMessage.newContents.rowDescription); //undefined console.info("request type " + fmMessage.requestType); //update,insert console.info("issuer conts " + fmMessage.fields['ISSUER'].contents); console.info("value conts " + fmMessage.fields['VALUE'].contents); var valueContents = fmMessage.fields['VALUE'].contents; category = fmMessage.fields['CATEGORY'].contents; imageModificationTime = (fmMessage.fields['IMAGE_MOD_TIME'].contents); issueDate = new Date(fmMessage.fields['ISSUE_DATE'].contents); expirationDate = new Date(fmMessage.fields['EXPIRATION_DATE'].contents); lastVerificationDate = new Date(fmMessage.fields['LAST_VERIFICATION_DATE'].contents); console.info("mod and ver ", imageModificationTime + " - " + lastVerificationDate); var issuerContents = fmMessage.fields['ISSUER'].contents.toUpperCase(); var myString = valueContents.replace(/[^0-9]/g, ''); console.info("myString and imageModificationTime ", myString + " - " + imageModificationTime); valueA = myString.slice(0, 1); valueB = myString.slice(1, 2); valueC = myString.slice(2, 3); valueD = myString.slice(10, 12); lenMyString = myString.length; //241037984007 totalValue = +valueA + +valueB + +valueC + 0; console.info("valueA valueB valueC valueD ", valueA + ", " + valueB + ", " + valueC + ", " + valueD + ", " + totalValue + ", " + lenMyString); console.info("mod date and ver date comparison ", imageModificationTime + " " + lastVerificationDate); }, //end afterrender fieldchange: function(fmMessage) { console.info(fmMessage.event, fmMessage); console.info(fmMessage.columnName); }, //end fieldchange fieldblur: function(fmMessage) { }, //end fieldblur beforepost: function(fmMessage) { console.info(fmMessage.event, fmMessage); var query = fmMessage.query; console.info("value " + fmMessage.fields['ISSUER'].contents); var valueContents = fmMessage.fields['VALUE'].contents; category = fmMessage.fields['CATEGORY'].contents; issueDate = new Date(fmMessage.fields['ISSUE_DATE'].contents); expirationDate = new Date(fmMessage.fields['EXPIRATION_DATE'].contents); lastVerificationDate = new Date(fmMessage.fields['LAST_VERIFICATION_DATE'].contents); var myString = valueContents.replace(/[^0-9]/g, ''); valueA = myString.slice(0, 1); valueB = myString.slice(1, 2); valueC = myString.slice(2, 3); valueD = myString.slice(10, 12); lenMyString = myString.length; //241037984007 totalValue = +valueA + +valueB + +valueC + 0; console.info("beforepost valueA valueB valueC valueD ", valueA + ", " + valueB + ", " + valueC + ", " + valueD + ", " + totalValue + ", " + lenMyString); console.info("mod date and ver date comparison ", imageModificationTime + " " + lastVerificationDate); console.info("request type beforepost " + fmMessage.requestType); //update,insert,delete var issuerContents = fmMessage.fields['ISSUER'].contents.toUpperCase(); let errorQuincy = false; console.info("running through inser validation ", imageModificationTime + " - " + lastVerificationDate + " - " + issueDate + " - " + expirationDate); if (lenMyString === 12 && issuerContents === 'MN' && category === 'DL') { // https://www.w3schools.com/js/js_comparisons.asp if (valueD != totalValue) { allErrorMessages += ' Please verify the DL Value you entered. The MN DL on this page does not pass the MN math formula.' errorQuincy = `Please verify the DL Value you entered. The MN DL on this page does not pass the MN math formula.`; } } else if (lenMyString != 12 && issuerContents === 'MN' && category === 'DL') { allErrorMessages += ' Please verify the DL Value you entered.' errorQuincy = `Please verify the DL Value you entered.`; } if (imageModificationTime > lastVerificationDate && category === 'DL') { console.info("imageModificationTime > imageModificationTime ", imageModificationTime + " - " + lastVerificationDate); allErrorMessages += ' Please verify the scanned image to the text fields above and update the Last Verification Date!' errorQuincy = `Please verify the scanned image to the text fields above and update the Last Verification Date!`; } if (issueDate === '' || isNaN(issueDate) && category === 'DL') { console.info("beforepost issueDate ", issueDate); allErrorMessages += ' Please select an Issue Date!' errorQuincy = `Please select an Issue Date!`; } if (expirationDate === '' || isNaN(expirationDate) && category === 'DL') { console.info("beforepost issueDate ", expirationDate); allErrorMessages += ' Please select an Expiration Date!' errorQuincy = `Please select an Expiration Date!`; } if (lastVerificationDate === '' || isNaN(lastVerificationDate) && category === 'DL') { console.info("beforepost issueDate ", lastVerificationDate); allErrorMessages += ' Please select a Last Verification Date!' errorQuincy = `Please select a Last Verification Date!`; } //} //console.info("hello beforepost friend ", fmMessage.query); if (fmMessage.query !== null) { console.log("fmMessage"); // alternatively use checkQueryObject within script to do complex table and field validation let query = fmMessage.query; if (query) { Ext.each(query.sequence, function(sequence) { Ext.each(sequence.transaction, function(transaction) { Ext.each(transaction.step, function(step) { Ext.each(step.record, function(record) { //if (record.operation.option !== "D" && record.tableName === "PERSON_ID") { if (record.operation.option === "D" && record.tableName === "PERSON_ID") { //if (record.tableName === "PERSON_ID") { console.info("what is this? ", record.operation.option); CR.Script.fmPost({ query: fmMessage.query }); } else if (errorQuincy) { CR.Script.fmSetField({ columnName: 'DESCRIPTION', //contents: '', error: errorQuincy }); } else { CR.Script.fmPost({ query: fmMessage.query }); } }); }); }); }); } } }, //end beforepost };