Hello, I’m actually generate on-the-fly some fields, deppending some criteria. And i want to assign for every field one variable, created on-the-fly too. All see work’s fine, the fields create good, and seems the varaible too, but when i assign the varaible to field, and put some data in the field, the value dissapear, and seems it’s not correctly assigned, any idea? here is the code.
function recrearCampos() {
// Limpiamos todo rastro de campos que puedan haber
solutionModel.revertForm("metadatosProceso_dtl");
var procesosMetadatosFs = forms.cofp_estandar_dtl.foundset.getSelectedRecord().tareas_to_procesos.procesos_to_rel_procesos_metadatos;
var metadatosLength = procesosMetadatosFs.getSize();
if (metadatosLength > 0) {
// Cogemos el actual formulario para poder generar los campos
var currentForm = solutionModel.getForm("metadatosProceso_dtl");
// Recorremos todos los metadatos que tenga
for (var i = 1, xLabel = horizontalLabelPosition, yLabel = verticalLabelPosition, xField = horizontalFieldPosition, yField = verticalFieldPosition; i <= metadatosLength; i++) {
var record = procesosMetadatosFs.getRecord(i);
var tipoCampo = null;
var tipoVariable = null;
// El tamaño por defecto
var campoTamany = 100;
// Si el campo tiene un tamaño definido le asignamos su tamaño
if (record.campo_tamany) campoTamany = record.campo_tamany;
// Dependiendo del tipo de campo le asignamos un tipo u otro
switch (record.campo_tipo) {
// Texto
case 1:
tipoCampo = JSField.TEXT_FIELD;
tipoVariable = JSVariable.TEXT;
break;
// Checkbox
case 2:
tipoCampo = JSField.CHECKS;
tipoVariable = JSVariable.INTEGER
break;
// Entero
case 3:
tipoCampo = JSField.TEXT_FIELD;
tipoVariable = JSVariable.INTEGER;
break;
// Número
case 4:
tipoCampo = JSField.TEXT_FIELD;
tipoVariable = JSVariable.NUMBER;
break;
// Fecha
case 5:
tipoVariable = JSVariable.DATETIME;
tipoCampo = JSField.CALENDAR;
break;
// Campo personalizado
case 6:
tipoVariable = JSVariable.INTEGER
tipoCampo = JSField.COMBOBOX;
break;
}
// Creamos la label
var label = currentForm.newLabel(record.campo_etiqueta, xLabel, yLabel, 100, 20);
// Creamos la variable
var variable = null;
if (currentForm.getVariable(record.campo_etiqueta) != null) {
variable = currentForm.getVariable("campo" + i);
} else {
variable = currentForm.newVariable("campo" + i, tipoVariable);
}
// Creamos el campo
var field = currentForm.newField(variable, tipoCampo, xField, yField, campoTamany, 20);
// Checkbox
if (record.campo_tipo == 2) {
field.transparent = true;
}
// Fecha
if (record.campo_tipo == 5) {
field.format = "mm/dd/yyyy";
}
// Combobox
if (record.campo_tipo == 6) {
// Obtenemos los metadatos detalle de la opción seleccionada
var query = "select metadato_det_descripcion, metadato_det_id from metadatos_det where metadato_id=?";
var data = databaseManager.getDataSetByQuery("wflow", query, [record.metadato_id], -1);
// Borramos la value_list si ya existia
solutionModel.removeValueList("vlst" + i);
// Creamos la value_list
var vlst = solutionModel.newValueList("vlst" + i, JSValueList.CUSTOM_VALUES);
// Asignamos los valores
application.setValueListItems("vlst" + i, data.getColumnAsArray(1), data.getColumnAsArray(2));
// Marcamos el campo como no editable, ya que se trata d eun combobox
field.editable = false;
// Asignamos la value_list al campo
field.valuelist = vlst;
}
field.name = "campo" + i;
label.labelFor = field.name;
label.transparent = true;
// añadimos 30 pixeles a la distancia vertical para que se vayan poniendo uno debajo de otro
yField += 20;
yLabel += 20;
}
}
controller.recreateUI();
}