Validate drop-down

Good afternoon,

I have configured some workflows in the opportunities module, but users are breaking that flow by not choosing the drop-down options in order, it is possible to validate that the user can chooses the correct option in the drop-down menu and does not allow him to save the record if Does not meet the flow.

That is, when creating the record, the value of the drop-down is: “pending”.

To activate the workflow, you must change from “pending” to “assigned” and after “assigned” to “delivered”.

The error is that the user chooses from “pending” to “delivered”, in doing so the flow fails and the corresponding actions are not activated.

thanks for your help. I use SuiteCRM 7.8.24

You can add some custom fields to control this. These fields would not be visible to the users, they are just auxiliary.

For example a field called last_stage_completed, where (in the end of each workflow) you record that the stage was successfully and validly completed.

Then in the other Workflows you could test this as a condition.

A better approach is to keep the users from choosing wrong options in the first place. this can be controlled with some validations on the edit view, or even with some custom JavaScript to hide the dropdown options that are invalid.

thanks pgr, using jquery I could solve it


Can you please share your solution here for others to learn, for the future? thanks!

Of course, create a script in custom/modules//views/view.edit.php, add the following code:

function display() {    
    function validaEstado(){
     let valSelect = $('#estado_preventa_c').val();

   if (valSelect == "pendiente"){
        $('#estado_preventa_c option[value="entregado"]' ).hide()
        $('#estado_preventa_c option[value="pend_info_cliente"]' ).hide()

   if (valSelect == "asignado"){
        $('#estado_preventa_c option[value="pendiente"]' ).hide()
        $('#estado_preventa_c option[value="entregado"]' ).show()
        $('#estado_preventa_c option[value="pend_info_cliente"]' ).show()

    if (valSelect == "entregado"){
         $('#estado_preventa_c option[value="asignado"]' ).hide()
         $('#estado_preventa_c option[value="pend_info_cliente"]' ).show()
echo $js;

and in the editviewdefs.php add the function validaEstado() and

1 => 
    array (
      0 => 
      array (
        'name' => 'estado_preventa_c',
        'studio' => 'visible',
        'label' => 'LBL_ESTADO_PREVENTA',
        'displayParams' => 
        array (
          'field' => 
          array (
            'onchange' => 'validaEstado();',
1 Like