Table method validateWrite() in D365
X++ Programming Language > D365 Table > Table Methods
9136
Answer:
Method validateWrite() will just check mandatory fields and is triggered when the record . Checks made by validateWrite() are the same as the super() call in validateField().So if your condition is not related to the value an application user enters in a specific field, you should put the validation in validateWrite().
/// /// Validate record /// ////// /// atnylaProgram 2017-08-16 rAnsari /// public boolean validateWrite() { boolean ret = true; atnylaProgramTable atnylaProgramTable; ret = this.validateData(); // record-level validations if (ret) { ret = this.checkDateOverlap(); } if (ret) { ret = super(); } return ret; }
checkFormat
/// /// Validate input string against a format string /// /// ///true if input matches format, else false ////// atnylaProgram 2017-08-16 rumman /// static boolean checkFormat(str _inputStr, str _formatStr) { //------------------------------- // # = numeric only // & = alpha only // ? = alphanumeric only // * = any char // else match char in formatStr //------------------------------- int iLen = strLen(_inputStr); int fLen = strLen(_formatStr); int idx; char iChar; char fChar; boolean ret = true; if(!_formatStr || !_inputStr) { ret = true; // must have both to validate return ret; } if (iLen != fLen) { ret = false; // not the same length return ret; } for (idx=1; idx<=flen; idx++) { iChar = subStr(_inputStr, idx, 1); fChar = subStr(_formatStr, idx, 1); switch (fChar) { case "#" : // numeric if (!match(':d',iChar)) { ret = false; } break; case "&" : // alpha if (!match(':a',iChar)) { ret = false; } break; case "?" : // alphanumeric if (!match(':n',iChar)) { ret = false; } break; case "*" : // any char if (!match('?',iChar)) { ret = false; } break; default: // must match char in format if (iChar != fChar) { ret = false; } break; } } return ret; }
This Particular section is dedicated to Question & Answer only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.