Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The 1st rule "Load Products" populates both the visible and hidden dropdowns with options from a database.

Code Block
/*member descriptionproductCode, productIdproductName, resultSet */
var x;
  
if (form.load) {
  eval('x=' + http.get('httphttps://localhost:8082app.frevvo.com/database/BIRT/productsallProducts'));   
  
    var opts1 = [];
     var opts2 = [];
  
    for (var i=0; i < x.resultSet.length; i++) { 
        if (x.resultSet[i]) {
             opts1[i] = x.resultSet[i].descriptionproductName;
             opts2[i] = x.resultSet[i].productIdproductCode;
        }
    }
  
   Products.options = opts1;
  PID.options = opts2;
  Products.value = opts1[0]; // default to 1st product option
  PID.value = opts2[0];

}

Finding a Selected Options Index

The 2nd rule Select Product ID keeps the hidden PID dropdown synchronized with the visible Products dropdown.

Code Block
}
if (Products.value.length > 0)

{ 
    var i; 
    for (var x in Products.options) {
        if ((Products.value + '=' + Products.value) === Products.options[x]){
             i = Products.options.indexOf(Products.options[x]);
        }
    }
 
  PID.value = PID.options[i] + ''; .split('=')[0];
}

In v4 rules using hidden dropdowns to keep descriptive option labels visible to the user while keeping cryptic database values hidden are often no longer necessary. Dropdown options have values distinct from the human visible option labels. The above can now be achieved with a single simpler rule:

...