BeanShell Validator for Checkbox
Hi Experts,
I´m needing validate the value in a checkbox located in a spreadsheet, anybody have an example about the code lines to do it?
I'm using this code currectly but it don't work, I'm remark the lines specifically with the problem.
I have tried saving the value in an String and later in an Boolean variable but I don't achieve do the evaluation.
public boolean validate(Element element, FormRowSet rows, FormData formData) {
boolean result = true;
if (rows != null && !rows.isEmpty()) {
int total = 0;
String haycancelacion = "No";
//Sum the values from column "amount"
for (FormRow row : rows) {
try {
int can_registrada = Integer.parseInt(row.getProperty("can_movimiento"));
int can_pedida = Integer.parseInt(row.getProperty("cantidad"));
int can_aprovisionada = Integer.parseInt(row.getProperty("cant_aprov"));
total += can_registrada;
var isChecked = row.getProperty("cancelar"); //Remark "This is the field Type Checkbox in the spreadsheet .
cantidad_maxima = (can_pedida - can_aprovisionada);
if (can_registrada > cantidad_maxima) {
String id = FormUtil.getElementParameterName(element);
formData.addFormError(id, "La cantidad aprovisionada no puede ser mayor a la cantidad solicitada menos la cantidad aprovisionada!!!! ");
result = false;
}
else {
//This is the first evaluation that I'm trying to do and don't work, the evaluation is bypassed (of course does not by the value of can_aprovisionada)
if (can_aprovisionada > 0 && isChecked == true) {
String id = FormUtil.getElementParameterName(element);
formData.addFormError(id, "No puede cancelar un requerimiento previamente aprovisionado!!!! ");
result = false;
}
//This is the second evaluation that I'm trying to do and don't work, the evaluation is bypassed (of course does not by the value of can_registrada)
else if (can_registrada == 0 && isChecked == true){
haycancelacion = "Si";
}
}
} catch (Exception e) { LogUtil.error("Sample app - Bulk Create Users form", e, "Store user error!!"); }
}
if (total == 0 && haycancelacion.equals("No")) {
String id = FormUtil.getElementParameterName(element);
formData.addFormError(id, "Aprovisione alguno de los artículos antes de continuar!!!!" + isChecked);
result = false;
}
}
return result;
}
//call validate method with injected variable
return validate(element, rows, formData);