4.1 SolutionModel Example

I just got finished showing off how to use the new SolutionModel functionality in the “What’s New in Servoy 4.1” Webinar that just ended. But I’ve been asked to put up the code - so here it is.

To use the code - create a form with 3 buttons (doesn’t matter what connection/table you use for the form).

There are 3 methods below - and they are in order of escalating complexity. Each one “builds” on the one before. So on your FIRST button - attach the FIRST method to the “onAction” event, on the SECOND button the SECOND method, and THIRD button, THIRD method.

IMPORTANT: This example assumes that you have a data connection called “example_data” (standard in the “default” install) - as well as the corresponding tables. If you don’t have that connection - then you can just modify the code for your own connection/tables/fields.

ENJOY!

==============
BUTTON 1 CODE

function newForm()
{
	solutionModel.removeForm('form1')
	
	//make a new form
	//creates a brand new form, under the given name, that persists only as long as the client session
	var myForm = solutionModel.newForm('form1', 'example_data', 'customers', 'svyWebCrm', false, 800, 600)
	//now you can add stuff to the form (under JSForm node)
	//add a label
	myForm.newLabel('Company', 20, 20, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('companyname', 101, 20, 200, 20)
	
	myForm.newLabel('Contact', 20, 42, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('contactname', 101, 42, 200, 20)
	
	myForm.newLabel('City bob', 20, 64, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('city', 101, 64, 200, 20)
	
	myForm.newLabel('Country', 20, 86, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('country', 101, 86, 200, 20)
	
	forms.form1.controller.show()
}

==============
BUTTON 2 CODE

function newFormTabpanel()
{
	solutionModel.removeForm('form1')
	solutionModel.removeForm('form2')
	
	//make a new form
	//creates a brand new form, under the given name, that persists only as long as the client session
	var myForm = solutionModel.newForm('form1', 'example_data', 'customers', 'svyWebCrm', false, 800, 600)
	//now you can add stuff to the form (under JSForm node)
	//add a label
	myForm.newLabel('Company', 20, 20, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('companyname', 101, 20, 200, 20)
	
	myForm.newLabel('Contact', 20, 42, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('contactname', 101, 42, 200, 20)
	
	myForm.newLabel('City', 20, 64, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('city', 101, 64, 200, 20)
	
	myForm.newLabel('Country', 20, 86, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('country', 101, 86, 200, 20)
	
	//new tabpanel
	var myPanel = myForm.newTabPanel('orders',20,120,430,200)
	
	//new listview for orders
	var myForm2 = solutionModel.newForm('form2', 'example_data', 'orders', 'svyWebCrm', false, 400, 200)
	myForm2.view = SM_VIEW.LOCKED_TABLE_VIEW
	
	var myField = myForm2.newTextField('orderid',10,10,100,20)
	myField.text = 'Order ID'
	
	myField = myForm2.newTextField('orderdate',10,20,100,20)
	myField.text = 'Order Date'
		
	myField = myForm2.newTextField('customerid',10,20,100,20)
	myField.text = 'Customer'
		
	myField = myForm2.newTextField('employeeid',10,20,100,20)
	myField.text = 'Employee'
	
	//add tab to tabpanel
	myPanel.newTab('','Orders',myForm2)  //optional last argument = relation
	
	forms.form1.controller.show()
}

==============
BUTTON 3 CODE

function newFormTabpanel2tabs()
{
	solutionModel.removeForm('form1')
	solutionModel.removeForm('form2')
	solutionModel.removeForm('form3')
	
	//make a new form
	//creates a brand new form, under the given name, that persists only as long as the client session
	var myForm = solutionModel.newForm('form1', 'example_data', 'customers', 'svyWebCrm', false, 800, 600)
	//now you can add stuff to the form (under JSForm node)
	//add a label
	myForm.newLabel('Company', 20, 20, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('companyname', 101, 20, 200, 20)
	
	myForm.newLabel('Contact', 20, 42, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('contactname', 101, 42, 200, 20)
	
	myForm.newLabel('City', 20, 64, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('city', 101, 64, 200, 20)
	
	myForm.newLabel('Country', 20, 86, 80, 20)
	//add a "normal" text entry field
	myForm.newTextField('country', 101, 86, 200, 20)
	
	//new tabpanel
	var myPanel = myForm.newTabPanel('orders',20,120,430,200)
	myPanel.transparent = true
	
	//new listview for orders
	var myForm2 = solutionModel.newForm('form2', 'example_data', 'orders', 'svyWebCrm', false, 400, 200)
	myForm2.view = SM_VIEW.LOCKED_TABLE_VIEW
	
	var myField = myForm2.newTextField('orderid',10,10,100,20)
	myField.text = 'Order ID'
	myField.name = 'orderid'
	
	myField = myForm2.newTextField('orderdate',10,20,100,20)
	myField.text = 'Order Date'
	myField.name = 'orderdate'
		
	myField = myForm2.newTextField('customerid',10,20,100,20)
	myField.text = 'Customer'
	myField.name = 'customerid'
		
	myField = myForm2.newTextField('employeeid',10,20,100,20)
	myField.text = 'Employee'
	myField.name = 'employeeid'
	
	//make a new relation
	var myRelation = solutionModel.newRelation( 'cust_to_orders',  'example_data',  'customers',  'example_data',  'orders',  SM_JOINTYPE.INNER_JOIN)
	myRelation.newRelationItem('customerid', '=', 'customerid')
	
	//make a new valuelist
	var myValueList = solutionModel.newValueList('employees', SM_VALUELIST.DATABASE_VALUES)
	myValueList.serverName = 'example_data'
	myValueList.tableName = 'employees'
	myValueList.setDisplayDataProviderIds('firstname', 'lastname')
	myValueList.setReturnDataProviderIds('employeeid')
	myValueList.separator = ' '
	myValueList.sortOptions = 'lastname asc, firstname asc'
	
	//modify the employeeid field on form2 to include the employee name
	myField = myForm2.getField('employeeid')
	myField.valuelist = solutionModel.getValueList('employees')
	myField.editable = false
	
	//new list view - extends the orders listview
	var myForm3 = solutionModel.newForm('form3', 'example_data', 'orders', 'svyWebCrm', false, 400, 200)
	
	//separate foundset
	myForm3.useSeparateFoundSet = true
	
	//extend it with form2 - makes a "copy"
	myForm3.extendsForm = myForm2
	
	
	//add tab to tabpanel
	myPanel.newTab('','Orders - Form 2 - ALL Orders',myForm2)  //optional last argument = relation
	myPanel.newTab('','Orders - Form 3 - Related Orders',myForm3, 'cust_to_orders')  //optional last argument = relation
	
	forms.form1.controller.show()
}

Thanks for a great preso Bob - you are a rather inventive lot at Servoy I have to say :wink: !

This is becoming a SUPER productive environment in which to develop :D .

Thanks, Kahuna! The new SolutionModel stuff is so AWESOME - it’s really mind-blowing the things you can do.

Hope to see you next week at the iPhone Application Demo “Building iPhone Applications with ZERO Code!” Register here: https://www1.gotomeeting.com/register/878257454