I am trying to create a script to pre-select the first value of a dropdown list in google sheets. The idea was that when I update a field, the rest would be updated automatically. Here you can see my sheet, when you change the value of A2 it lists some values that come out from a query in B2, those values will be the ones that compose the possible values of the list of A10, with my script this part is automatically updated as I modify A2. My problem starts with A11, the list is composed by another query but that is in another sheet, in the script I have put to appear an alert to check its value during this development and it always returns #N/A although in the other sheet the field is updated correctly. I have checked this operation with static fields from the other sheet and it works correctly.
Here it's my script so far:
function onEdit(e) {
const range = e.range;
const ss = SpreadsheetApp.getActiveSpreadsheet();
const s1 = ss.getSheetByName("Ore calculator");
const s2 = ss.getSheetByName("BBDD");
var valor = s1.getRange('B2').getValue();
var valor2 = s2.getRange('I2').getDisplayValues();
SpreadsheetApp.getUi().alert(valor2);
if(s1.getName() != "Ore calculator" || range.columnStart != 1 || range.rowStart < 2 || range.rowEnd > 2) return;
s1.getRange('A10').setValue(valor);
s1.getRange('A11').setValue(valor2)
}