Валідація
It is possible in the Form Script define attribute validation for scalar attributes, using attribute validation events:
<dataObject>_validateAttribute_<attributeCode><dataObject>_validateNativeAttribute_<attributeCode>
As it should be clear from the pattern of event name, each variation of event filter events by data object (such as "task" or "document"), attribute kind ("custom" - from attribute library or "native" - entity attribute), and attribute code.
Event object itself contains the following properties, specific to just validateAttribute events:
dataObjectattributeCodeattributeKindvalue
Validation events functions should be only SYNCHRONOUS.
Examples
Example: require "age" numeric document attribute to be 18+
Use document_validateAttribute_age event to set up validation rule:
module.exports = {
document_validateAttribute_age(event) {
if (event.value < 18) {
return 'He should be of legal age'
}
}
}
Example: validate document image attribute to be uploaded and have at least 2 signatures and be 100KB+
module.exports = {
document_validateNativeAttribute_docImage(event) {
const docFile = event.document.getNativeFileAttribute()
if (!docFile.isUploaded) {
return 'The document image is required'
}
if (docFile.signatures.length < 2) {
return 'The document image should contain at least 2 signatures'
}
if (docFile.fileInfo.size > 100) {
return 'The file size should be less than 100KB'
}
}
}