// Function to populate a specified dropdown based on the selections of "Group 1 - 1:" through "Group 1 - 6:" function populateDropdown(dropdownFieldName) { // Retrieve the current selections from Group 1 dropdowns var groupSelections = [ this.getField("Group 1 - 1:").valueAsString, this.getField("Group 1 - 2:").valueAsString, this.getField("Group 1 - 3:").valueAsString, this.getField("Group 1 - 4:").valueAsString, this.getField("Group 1 - 5:").valueAsString, this.getField("Group 1 - 6:").valueAsString ]; // Filter out empty selections var validSelections = groupSelections.filter(function(selection) { return selection !== ""; // Exclude empty or unselected values }).map(String); // Convert all selections to strings // Forcefully include "49rs" if it's selected but not recognized if (validSelections.indexOf("49rs") === -1 && groupSelections.includes("49rs")) { validSelections.push("49rs"); } // Sort and deduplicate the selections var uniqueSelections = [...new Set(validSelections.sort())]; // Store the current value of the specified dropdown var dropdown = this.getField(dropdownFieldName); var currentValue = dropdown.valueAsString; // Clear existing items in the specified dropdown dropdown.clearItems(); // Populate new options in the specified dropdown based on the valid selections dropdown.setItems(uniqueSelections); // Retain the previous selection if it exists in the new options if (uniqueSelections.indexOf(currentValue) !== -1) { dropdown.value = currentValue; } }