Problems with the history.removeForm() method

Hello, I have a problem and i don’t know why! The problem is i have a form called “encolumnadoResultados_tbl” and i want to modify with the solution model. First I remove the form with this instruction:

history.removeForm("encolumnadoResultados_tbl");

later make all the things with the solution model, add fields, dataproviders and more. But when i quit of the screen, and later enter again. The error is this


I don’t know why the elements of my form are deleted or if i do anything wrong. I use the servoy framework and I don’t know if have any interference. Any idea?

If i coment the line of history and the operations before of this, the error don’t ocurre, for this reason i think the problem is with the history.removeForm().

without seeing way more code what you exactly do, its very hard to help

Hello, this is the function that i execute, and use the solutionModel to change the dataproviders and create the new form elements. With the first acces into the form i have no problem, but when i close the tab of the framework and enter againd, show me the error.

function fillThirdTab() {

	// The foundset with the sheets
	var hojasFs = forms.hojasBasicInfo_tbl.foundset;

	// The array with the field names
	var tableFieldsArray = new Array("hoja_codigo", "hoja_fecha");

	// The array with the field types
	var types = new Array(DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.DATETIME);

	// The tests of the selected element
	var testsOfElement = getTestsOfElement();

	// The array with the valid tests
	var validTests = new Array();

	// Remove from history
	history.removeForm("encolumnadoResultados_tbl");

	// Get the form
	var myForm = solutionModel.getForm("encolumnadoResultados_tbl");
	deleteFields(myForm);

	// Get the info of one field
	var selectField = myForm.getField("hoja_fecha");
	var border = selectField.borderType;
	var locationFieldX = selectField.x;
	var locationFieldY = selectField.y;

	// Get the info of one label
	var selectLabel = myForm.getLabel("hoja_fecha_label");
	var locationLabelX = selectLabel.x;
	var locationLabelY = selectLabel.y;

	// Fill all the headers
	for (var i = 1; i <= testsOfElement.getSize(); i++) {

		// Get one test
		var oneTest = testsOfElement.getRecord(i);

		// If the test are selected add
		if (selectedTests[oneTest.ensayo_id] == 1) {

			// The field name
			var fieldName = oneTest.ensayos_to_ensayos_std.ensayo_codigo + "_" + oneTest.ensayo_id;

			// Put the header title
			tableFieldsArray.push(fieldName);

			// Create new field for the info
			var newField = myForm.newField(fieldName, JSField.TEXT_FIELD, locationFieldX + 10, locationFieldY + 20, 200, 20);
			newField.name = fieldName;
			newField.borderType = border;
			newField.editable = false;

			// Create a new label for the field
			var newLabel = myForm.newLabel(oneTest.ensayos_to_ensayos_std.ensayo_codigo, locationLabelX, locationLabelY + 20, 100, 200);
			newLabel.labelFor = fieldName;
			newLabel.styleClass = "table";

			// Add the type into the array of types
			types.push(DM_COLUMNTYPE.TEXT);

			// add the test to the valid tests
			validTests.push(oneTest.ensayo_id);
		}
	}

	// Convert the array into a string
	var testsToFind = validTests.join("||");

	// Create a new dataset with the fields
	var dataSet = databaseManager.createEmptyDataSet(0, tableFieldsArray);

	// Travel all the foundset and put the info into an array
	for (var j = 1; j <= hojasFs.getSize(); j++) {

		var sheetsLineTestsArray = new Array();

		// Get one sheet
		var oneSheet = hojasFs.getRecord(j);

		// Get the lines of the sheet
		var linesOfSheet = oneSheet.hojas_to_hojas_lin.duplicateFoundSet();

		// Find all the lines with the status 3 or 4
		linesOfSheet.find();
		linesOfSheet.hoja_lin_estado = 3 + "||" + 4;
		if (numericalSheets == 1) linesOfSheet.hoja_lin_valor = "!^=";
		linesOfSheet.ensayo_id = testsToFind;
		linesOfSheet.search();

		// Sort the foundset by date and ensayo_id
		linesOfSheet.sort("hoja_lin_fecha_plan asc");

		// Travel all the sheet lines
		for (var k = 1; k <= linesOfSheet.getSize(); k++) {

			// The array for the new record
			var newRecord = new Array();

			// Get one sheet
			var oneSheetLine = linesOfSheet.getRecord(k);
			var nextSheetLine = linesOfSheet.getRecord(k + 1)

			sheetsLineTestsArray[oneSheetLine.ensayo_id.toString()] = oneSheetLine.tmp_resultado;
			// If the date are different
			if (globals["compareDates"](oneSheetLine.hoja_lin_fecha_plan, nextSheetLine.hoja_lin_fecha_plan) != 0) {

				newRecord.push(oneSheetLine.hojas_lin_to_hojas.hoja_codigo);
				newRecord.push(oneSheetLine.hoja_lin_fecha_plan);

				for (var l = 0; l < tableFieldsArray.length - 2; l++) {
					/**@type {String}*/
					var fieldTitle = tableFieldsArray[l + 2];
					var fieldParts = fieldTitle.split("_");
					var testCode = fieldParts[0];
					var testId = utils.stringToNumber(fieldParts[1]);

					if (sheetsLineTestsArray[testId]) {
						newRecord.push(sheetsLineTestsArray[testId]);
					} else {
						newRecord.push("");
					}
				}
				sheetsLineTestsArray = new Array();

				// Add the record to the dataset
				dataSet.addRow(newRecord);
			}
		}
	}

	var dataSource = dataSet.createDataSource("test_info", types);

	// Set the datasource
	myForm.dataSource = dataSource;

	myForm.getField("hoja_codigo").dataProviderID = "hoja_codigo";
	myForm.getField("hoja_fecha").dataProviderID = "hoja_fecha";
}

And I don’t know, why after the first acces, and close the form delete all of my elements in the form, If i never in the function of cleaned up the elements in the form delete the first two.

function deleteFields(myForm) {
	var fieldsArray = myForm.getFields();
	for (var i = 0; i < fieldsArray.length; i++) {
		/**@type {JSField}*/
		var oneField = fieldsArray[i];
		if(oneField.name.indexOf("hoja_")==-1){
			myForm.removeField(oneField.name)
		}
	}
}

Thanks for all.

Hello. I solved the problem using the controller.recreateUI instead of history.removeForm, at the end of the changes with the solution model.