Hello!
I have to do a validation in the Employee Registration, there can't be two employees with the same file number. For that, add a validation on the page and use ESQ to verify the data in the database.
The problem is that the result of the validation method is always executed before the result that ESQ GetEntityCollection() returns. I need to establish the error message after evaluating the result of the query.
Is there any way or alternative of waiting for the result of the ESQ and then validating to establish the error message?
I appreciate your help.
I Attach the code:
validarNroLegajo: function() {
var invalidMessage = "";
var repetidos = 0;
//Creo consulta para Empleado
var consultaEmpleado = this.Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "Employee"
});
//Cuento NroLegajos
consultaEmpleado.addAggregationSchemaColumn("UsrNroLegajo", Terrasoft.AggregationType.COUNT, "NroLegajoRepetido", Terrasoft.AggregationEvalType.ALL);
//Filtro por Nro de legajo
var filtroNroLegajo = consultaEmpleado.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrNroLegajo", this.get("UsrNroLegajo"));
//Filtro por Id de empleado
var filtroId = consultaEmpleado.createColumnFilterWithParameter(Terrasoft.ComparisonType.NOT_EQUAL, "Id", this.get("Id"));
//Agrego filtros a la consulta
consultaEmpleado.filters.add("filtroNroLegajo", filtroNroLegajo);
consultaEmpleado.filters.add("filtroId", filtroId);
//debugger;
consultaEmpleado.getEntityCollection(function(result) {
debugger;
if (result.success) {
repetidos = result.collection.collection.items["0"].values.NroLegajoRepetido;
}
}, this);
debugger;
if (repetidos > 0)
{
invalidMessage = this.get("Resources.Strings.ValidacionNroLegajo");
}
return {
// Validation error message displayed in the data window
// when saving a page.
fullInvalidMessage: invalidMessage,
// Validation error message displayed under the control item.
invalidMessage: invalidMessage
};
}
Regards,