package com.servicemax.example;
import com.servicemax.core.validator.OperationValidator;
import java.util.Map;
class MyValidator extends OperationValidator {
public Object realValidator(Map<String, Object> params) {
//verify whether record's application value is null
if(recordUnderValidation.io_application == null) {
//if the value is null, log the error
logger.error("The Application field is blank for Source object {}", recordUnderValidation.io_name)
//and generate a field validation error to be displayed by the UI
addFieldValidationError('io_application', "The \"Application\" Field can not be null.") // This adds an error to the validation, then record will not be saved
}
}
}
package com.servicemax.example;
import com.servicemax.core.validator.OperationValidator;
import java.util.Map;
class MyAppointmentValidator extends OperationValidator {
public Object realValidator(Map<String, Object> params) {
//If the status of the appointment is Accepted
if(recordUnderValidation.svmx_workflow.toString() == "Accepted") {
//verify that the Start and End Time fields are not being changed
if(recordUnderValidation.isFieldChanged("svmx_start_datetime")) {
//if Start is trying to be changed, generate a field validation error to be displayed by the UI
addFieldValidationError('svmx_start_datetime', "The \"Start\" field cannot be changed if Status is Accepted.") // This adds an error to the validation, then record will not be saved
}
if(recordUnderValidation.isFieldChanged("svmx_end_datetime")) {
//if End is trying to be changed, generate a field validation error to be displayed by the UI
addFieldValidationError('svmx_start_datetime', "The \"End\" field cannot be changed if Status is Accepted.") // This adds an error to the validation, then record will not be saved
}
}
}
}
|
|
For details on how to configure record-level custom validation, see Configuring Record-Level Custom Validation in Service Board for Implementers.
|