Application Logging Validation Code Examples
The following custom validation code shows how to log debugging messages in the Application Log, and also how to make a comparison by using an Option List field.
* 
To ensure that messages are effectively logged, you must configure the Application Log Level option in the User Preferences object.
package com.servicemax.sb.customization

import com.servicemax.core.validator.OperationValidator;

class CustomTestValidator extends OperationValidator {

//This is the method automatically called to execute the validation
@Override
public Object realValidator(Map<String, Object> parameters) {
//get the application log associated with the current executing user
def appLog = parameters["iop_application_logger"]
try {
//the debug message will be logged only if the logging level is set accordingly (DEBUG) under 'User Preferences'-> 'Application Log Level'
appLog.debug("Start validating record '$recordUnderValidation.svmx_name'")

// check that record's priority is not 'High'
if (recordUnderValidation.svmx_priority[0].getName() == 'High') {
// This adds an error to the validation, then record will not be saved
addFieldValidationError('svmx_priority', "The \"Priority\" field is invalid.")
}
appLog.debug("Finish validating record '$recordUnderValidation.svmx_name'")
} catch(Exception e) {
appLog.error("Error when trying to validate record {}. Error: {}", recordUnderValidation.svmx_name, e.getMessage())
throw e
}
}
}
* 
For details on configuring custom data validation, see Working With Data Validation Options in Service Board for Implementers.
For more information:
Was this helpful?