Promote Dropdown dinamically
Hello, I'm trying to fill a dropdown by code.
Let me explain, I have a report, which when selected, shows me a screen where the user can select the date range and I would like to put a dropdown with the list of departments of a method (table).
Well, there's no way, I've looked at examples here, in google, and in... chatgpt. But it always fails me when executing the code, it always gives me the error:
Event handler failed with message: TypeError: Cannot read properties of null(reading 'appendChild')[function onload$user$handler(e) {
try {
if (onload1(e) === false) return false;
} catch (exp) {
aras.AlertError(aras.getResource('', 'ui_methods_ex.event_handler_failed'), aras.getResource('', 'ui_methods_ex.event_handler_failure_msg', exp.description ? exp.description : (exp + ' [' + arguments.callee.toString() + ']')), aras.getResource('', 'common.client_side_err'));
return false;
}
}]
This is my code, one of them, I have tried many ways.
// Obtén una referencia al ListBox
var listBox = document.getElementById("Departamentos");
// Crea un nuevo elemento de opción
var option = document.createElement("option");
// Establece el valor y el texto del elemento de opción
option.value = "valor1";
option.textContent = "Opción 1";
// Agrega el elemento de opción al ListBox
listBox.appendChild(option);
As I see, or I think, document.getElementById doesn't take well, I'm failing in something. I pu an a alert(listBox); and return NULL.
This is the structure of where the field is:
All the code is executed when entering the form, in the event "onLoad"
I have seen examples in the forum with the use of "getFieldComponentByName", but here in the company we have Version 11.0 SP9 Build: 6549 installed and it doesn't work. Examples from angela and Christoper Gillis.
Too many thanks!!!
Well, the way to work with dropdowns changed around 3 times over the years. There is a difference between 11SP9, 11SP11 and 11SP15 :).
General tip: Always add a comment sections on the top of your code that indicates which version it was build for and add some descriptions.
This way I found this Innovator 11SP9 code that filled a dropdown in Form based on a List item:
var inn = new Innovator();
// Get dropdown element from Form
var div_startpage = getFieldByName("mydropdown").id;
var control_items = div_startpage.substring(0, div_startpage.indexOf("span"));
var select = document.getElementById(control_items);// Get list values
var listValues = [];
listValues = aras.getListValues("BFDEFE0CEE174B...."); // id of List "xy"
for (var i = 0; i < listValues.length; i++) {
var value = aras.getItemProperty(listValues, "value");
var label = aras.getItemProperty(listValues, "label");
var option = document.createElement('option');
select.options = new Option(label, value); // fill dropdown list
}No Idea if it works :D