Custom Data Validation Source Code
The Max platform provides several Groovy template classes to support source code development for custom data validation. To configure validators, you create custom validation classes that inherit from and extend one of these classes.
OperationValidator Class
The OperationValidator class includes methods to access records, fields, and loggers. This class also contains helper methods to add validation errors when failures occur. The following example shows how to create a custom class for the OperationValidator class and implement custom logic.
package com.servicemax.example;

import com.servicemax.core.validator.OperationValidator;

class MyValidator extends OperationValidator {

public Object realValidator(Map<String, Object> params) {
// add validation logic here
}
}
This class provides the following methods to add validation errors at the record, field and relationship levels. You can call any of these methods in validation code to automatically add validation errors into responses that appear in the UI.
//Adds a validation error that affects the full record
protected void addRecordValidationError(String errorMessage)

//Adds a field validation error
protected void addFieldValidationError(String fieldFullIdentifier, String errorMessage)

//Adds a relationship validation error
protected void addRelationshipValidationError(String relationshipFullIdentifier, String errorMessage)
* 
The custom validation class must extend the OperationValidator class and implement custom logic by using the realValidator method. Additionally, be sure to include the Groovy package definition in the source, and use the fully qualified name of the class in the Class Name field in the Operation record that you configure for custom validation. This applies at the record, field, and relationship levels.
RelationValidator Class
The RelationValidator class includes methods to validate source and target records for relations and loggers and determine whether related records are linked or unlinked. This class also contains helper methods to add validation errors when failures occur. The following example shows how to create a custom class for the RelationValidator class and implement custom logic.
package com.servicemax.example;

import com.servicemax.core.validator.RelationValidator;

class MyRelationValidator extends RelationValidator {

public Object realValidator(Map<String, Object> params) {
// add validation logic for the relation here
.
.
.
logger //contains a reference to the logger
relationUnderValidation //contains a reference to the relation being validated
}
}
* 
The custom validation class must extend the RelationValidator class and implement custom logic by using the realValidator method. Additionally, be sure to include the Groovy package definition in the source, and use the fully qualified name of the class in the Class Name field in the Operation record that you configure for custom validation. This applies at the record, field, and relationship levels.
This class provides the following methods:
//Returns the source record of the relation
protected MaxObject getRelationSource()

//Returns the target record of the relation
protected MaxObject getRelationTarget()

//Returns the UUID of the Object of the source record
protected UUID getRelationSourceObjectUUID()

//Returns the UUID of the Object of the target record
protected UUID getRelationTargetObjectUUID()

//Indicates whether the relation is being created, it is a new link between the records
protected boolean isRelationLinking()

//Indicates whether the relation is being removed, it is an unlink between the records
protected boolean isRelationUnlinking()

//Indicates whether any of the endpoints of the relation is also being removed
protected boolean isEndpointBeingDeleted()

//Adds a general validation error with the given message
protected void addValidationError(String errorMessage)

//Adds a general validation error which will be translated according to the translation identifier and parameters
protected void addValidationErrorWithTranslation(String translationFullIdentifier, String... parameters)

//Adds a validation error at the relationship level with the given message if no params are indicated. If parameters are passed it will try to translate the message
protected void addRelationshipValidationError(String errorMessage, Object... params)

//Adds a general validation warning with the given message
protected void addValidationWarning(String warningMessage)

//Adds a general validation warning which will be translated according to the translation identifier and parameters
protected void addValidationWarningWithTranslation(String translationFullIdentifier, String... parameters)

//Adds a validation warning at the relationship level with the given message if no params are indicated. If parameters are passed it will try to translate the message
protected void addRelationshipValidationWarning(String warningMessage, Object... params)
* 
For details on how to configure custom data validation, see Working With Data Validation Options in Service Board for Implementers.
For more information:
Was this helpful?