BPM, Workflow, and Case

 View Only

 Issue on button onClick event

jhon wick's profile image
jhon wick posted Tue February 04, 2025 08:45 AM

i have a button that fires the following code on click

// List of filter options:
// 1 - Por Fecha
// 2 - Por Sucursal
// 3 - Por Sucursal Y Estado
// 4 - Por Sucursal Y Fecha
// 5 - Por Sucursal, Fecha Y Estado
// 6 - Por Solicitud
// 7 - Por Número de Documento
// 8 - Por Estado Y Fecha
var fallidos = 0;
var campos = {
    fechaDesde: me.ui.getSibling('fecha1'),
    fechaHasta: me.ui.getSibling('fecha2'),
    sucursal: me.ui.getSibling('sucursal'),
    solicitud: me.ui.getSibling('solicitud'),
    documento: me.ui.getSibling('documento'),
    nroDocumento: me.ui.getSibling('documento2'),
    estado: me.ui.getSibling('estado')
};
var filtroSeleccionado = me.ui.getSibling('filtroBusqueda').getSelectedItem()||'';
function validateField(field, errorMessage) {
    console.log('ejecutando funcion validateField');
    if (!campos[field].getData()) {
        fallidos++;
        campos[field].setValid(false, errorMessage);
    } else {
        campos[field].setValid(true);
    }; 
};
switch (filtroSeleccionado) {
    case "Por Fecha": // Por Fecha
        validateField('fechaDesde', 'Debe seleccionar una fecha Desde valida.');
        validateField('fechaHasta', 'Debe seleccionar una fecha Hasta valida.');
        break;

    case "Por Sucursal": // Por Sucursal
        validateField('sucursal', 'Debe seleccionar una Sucursal valida.');
        break;

    case "Por Sucursal Y Estado": // Por Sucursal Y Estado
        validateField('sucursal', 'Debe seleccionar una Sucursal valida.');
        validateField('estado', 'Debe seleccionar un Estado valido.');
        break;
    case "Por Sucursal Y Fecha": // Por Sucursal Y Fecha
        validateField('sucursal', 'Debe seleccionar una Sucursal valida.');
        validateField('fechaDesde', 'Debe seleccionar una fecha Desde valida.');
        validateField('fechaHasta', 'Debe seleccionar una fecha Hasta valida.');
        break;
    case "Por Sucursal, Fecha Y Estado": // Por Sucursal, Fecha Y Estado
        validateField('sucursal', 'Debe seleccionar una Sucursal válida.');
        validateField('fechaDesde', 'Debe seleccionar una fecha Desde valida.');
        validateField('fechaHasta', 'Debe seleccionar una fecha Hasta valida.');
        validateField('estado', 'Debe seleccionar un estado válido.');
        break;
    case "Por Solicitud": // Por Solicitud
        validateField('solicitud', 'Debe ingresar un Nro de Solicitud valida.');
        break;
    case "Por Número de Documento": // Por Número de Documento
        validateField('documento', 'Debe ingresar un tipo de documento valido.');
        validateField('nroDocumento', 'Debe ingresar un Nro Documento valido.');
        break;
    case "Por Estado Y Fecha": // Por Estado Y Fecha
        validateField('fechaDesde', 'Debe seleccionar una fecha Desde valida.');
        validateField('fechaHasta', 'Debe seleccionar una fecha Hasta valida.');
        validateField('estado', 'Debe seleccionar un estado válido.');        break;
    default:
    	  fallidos++;
        break;
}
return fallidos === 0;

and it works fine but its not validating if the component (sucursal for example) is an object. i add this line to the validation 

    if (!campos[field].getData() || campos[field].getData().toJson()=='{"name":"","value":""}') {

but now when i load the page i get this error on console.

Error registering [eventON_CLICK] event handling for view buscar: Unexpected token ')'

i tried the same script on a new coach and it works as intended (the select "sucursal" shows the validation error when no value is selected).
what could be the issue?

Julie Garza's profile image
Julie Garza

If this script works when you add to a new coach, I would try to delete everything from your original button on click script, see if the error is resolved, then add the script back. It could been caching issue. If removing the script doesn't remove the error, then you should just add a new button and remove the one with the error.

I usually see this error when I am missing a semicolon on the line before the listed character so you can check if maybe your script was missing a semicolon somewhere. Perhaps the script in the new coach that works as intended has a semicolon where your original button script did not.