Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#814344
What's the best way to keep a dropdown of a few thousand entries updated weekly? I have data being added and removed.

I had been using a PM Table to populate my dropdown but didn't realize that deleting an entry will also delete it from completed and in-process cases. I had considered converting the PM Table data into an array variable but it seems like it would be needlessly clunky to keep a massive array in every case. Is there a better option out there?

Thanks!
#814359
If you are displaying the same field multiple times in different DynaForms in a process, then in the first DynaForm, you can use a dropdown and then after that you can use a suggest box to display the same variable. The suggest box will preserve the value, even if it is deleted from the database.

Another option is to use JavaScript to automatically add the deleted option to the list of options in the dropdown box.

This JavaScript code will preserve the original value, by adding it as an option to the dropdown box:
Code: Select all
var dropdownId = "paymentMethod"; //set to ID of dropdown field 
var drpValue = $("#"+dropdownId).getValue();

if (drpValue != '') {
  var drpLabel = $("#"+dropdownId).getText();
  var aOpts = getFieldById(dropdownId).model.attributes.options;
  var found = false;

  //search for the dropdown's current value in its list of available options:
  for (idx in aOpts) {
    if (aOpts[idx].value == drpValue) {
      found = idx;
      break;
    }
  }

  //if the current value of the dropdown is not in the list of options,
  //then the value has been deleted from the database, so temporarily
  //add it to the list of options so the user can see it:
  if (found === false) {
    $("#"+dropdownId).getInfo().options.push({value: drpValue, label: drpLabel});
    $("#form\\["+dropdownId+"\\]").append( $(new Option(drpLabel, drpValue)) );
    getFieldById(dropdownId).setValue(drpValue);
  }
}
#822375
Sighto wrote: Thu Jan 10, 2019 8:13 pm Thanks so much for your help before!! What would you need to change so it would work in a dropdown within a grid?
Here is an example how to retain deleted options in dropdowns in grids.

Primero, tus comillas estan mal y olvidaste termin[…]

First of all, you are using JavaScript, not Java. […]

Stop submit from javacript

Do it this way: form = $("#637207031573dcea[…]

I can't find the database table where this informa[…]