Need a little help with SolutionModel

Good afternoon from Gran Canaria.

I need a little help with SolutionModel.

My customers form has a tabpanel with some forms inside it. In the irst show of the form a create a new tab from a form that is created with SolutionModel here is the code:

/**
 * @properties={typeid:24,uuid:"A927A8FC-23D6-4A70-AB43-C48F2BC3DCC3"}
 */
function addBalanceTab(){
	var lcSQL="SELECT h.fecha, h.idcliente, h.concepto, h.debe, h.haber, \
		SUM(h.debe-h.haber) OVER(PARTITION BY h.idcliente ORDER BY h.idcliente, h.fecha) AS saldo \
		FROM historico_clientes h \
		WHERE h.idinquilino=? AND h.idcliente=? \
		ORDER BY h.idcliente, h.fecha";
	var aArgs=new Array();
	aArgs.push(globals.currentInquilinoID);
	aArgs.push(foundset.idcliente);
	var _ds=databaseManager.getDataSetByQuery('gsdespachos',lcSQL,aArgs,-1);
	var uri=_ds.createDataSource('extracto');
	
	var frmExtracto=solutionModel.newForm('frmExtractoClientes',uri,'listafiltros',false,150,650);
	frmExtracto.extendsForm='lstExtractoClientes_GSDespachos';
	var txtFecha=frmExtracto.newTextField('fecha',1,1,90,20);
	txtFecha.editable=false;
	txtFecha.format='dd-MM-yyyy';
	txtFecha.styleClass='listafiltros';
	var txtConcepto=frmExtracto.newTextField('concepto',20,20,260,20);
	txtConcepto.editable=false;
	txtConcepto.styleClass='listafiltros';
	var txtDebe=frmExtracto.newTextField('debe',30,30,100,20);
	txtDebe.editable=false;
	txtDebe.format='#,##0.00';
	txtDebe.styleClass='listafiltros';
	txtDebe.horizontalAlignment=SM_ALIGNMENT.RIGHT
	var txtHaber=frmExtracto.newTextField('haber',40,40,100,20);
	txtHaber.editable=false;
	txtHaber.format='#,##0.00';
	txtHaber.styleClass='listafiltros';
	txtHaber.horizontalAlignment=SM_ALIGNMENT.RIGHT;
	var txtSaldo=frmExtracto.newTextField('saldo',50,50,100,20);
	txtSaldo.editable=false;
	txtSaldo.format='#,##0.00';
	txtSaldo.styleClass='listafiltros';
	txtSaldo.horizontalAlignment=SM_ALIGNMENT.RIGHT;
	var tb=elements.tabHistoricos.addTab(forms['frmExtractoClientes'], 'tabExtracto', 'Extracto', null, null, null, null);
}

This works pretty well I can see the new tab but now I need to reload that form data everytime the record is changed in the customers form. Of course I have to put the code in the onRecordSelection of the customers form, but how can I reload the foundset of the form frmExtractoClientes?

Thanks in advance.

You should be able push new records to that new in memory foundset (URI) you created and then just do a loadAllRecords() on the solutionModel form and it will just display whatever you had added to the URI. I would separate the code for building your form and the code that runs your SQL statement. You only need to create the form once, but the URI has to be refreshed on each record selection.

Thanks Bobby. I what understand is that I have to separate the code in two pieces. One to create the tab and other to be run each time the record changes, but what I do not understand is the way I refresh the URI.

If I put the code to create the tab in the onShow event of the customers form, only if firstShow, I understand that I need to have the dataSource ready so I can attach dataProviders to my textFileds, isn´t it? Once I have attached that dataSource to my frmExtractoClientes form, trhu the newForm() method, how do I refresh that dataSource.

Maybe I´m missunderstanding something in the way this works and it would be really appreciated if you could please clarify those points?

Thanks in advance.

First off… Yes. That is a good way to set it up.

Think of the URI as any other foundset. In fact you can get a JSFoundset object by calling databaseManager.getFoundset(_uri).

But in your case you are wanting to run a SQL statement each time. So you would just call this code again and the foundset of the form should update itself because it is tied to the URI ‘extracto’…

var lcSQL="SELECT h.fecha, h.idcliente, h.concepto, h.debe, h.haber, \
      SUM(h.debe-h.haber) OVER(PARTITION BY h.idcliente ORDER BY h.idcliente, h.fecha) AS saldo \
      FROM historico_clientes h \
      WHERE h.idinquilino=? AND h.idcliente=? \
      ORDER BY h.idcliente, h.fecha";
   var aArgs=new Array();
   aArgs.push(globals.currentInquilinoID);
   aArgs.push(foundset.idcliente);
   var _ds=databaseManager.getDataSetByQuery('gsdespachos',lcSQL,aArgs,-1);
   var uri=_ds.createDataSource('extracto');

I tried it just to make sure it works :wink:

I just used solutionModel to set the datasource of an existing form to a URI. Then my onRecordSelection just runs a SQL statement each time with a different parameter.

function onShow() {
var _args = [foundset.customerid]
	var _ds = databaseManager.getDataSetByQuery("example_data","select * from customers where customerid = ?",_args,-1)
	var _uri = _ds.createDataSource("customers_ds");
	
	_jsForm = solutionModel.getForm("table_frm");
	_jsForm.dataSource = _uri;
	forms.table_frm.controller.recreateUI();
	//A form variable set to false so that the on record selection won't run the first time
	_flag = true;
}


function onRecordSelection(event) {
	if (_flag) {
		var _args = [foundset.customerid];
		var _ds = databaseManager.getDataSetByQuery("example_data","select * from customers where customerid = ?",_args,-1);
		var _uri = _ds.createDataSource("customers_ds"); //The form(s) foundsets linked to this URI should auto update
		//forms.table_frm.foundset.loadAllRecords();  //I found this wasn't even necessary
	}
}

Thanks Bobby, works really well !!!