DBTreeview Question

Hello Everybody

I use the DBtreeview to show information about our LAN/WAN.
In my table all records have an ID and a PARENTID

This code works:

var _binding = elements.objtreeview.createBinding(controller.getServerName(), controller.getTableName());
_binding.setNRelationName("ivid_to_ivparentid"); 
_binding.setTextDataprovider("ivid"); 

elements.objtreeview.setTreeColumnHeader("Netzknoten");

elements.objtreeview.createColumn(controller.getServerName(), controller.getTableName(), 'Name', 'netzname');
elements.objtreeview.createColumn(controller.getServerName(), controller.getTableName(), 'City', 'city');
elements.objtreeview.createColumn(controller.getServerName(), controller.getTableName(), 'Location', 'location');
elements.objtreeview.createColumn(controller.getServerName(), controller.getTableName(), 'Street', 'street');

and show a result like this(plus city,location and street for each record)
root
–1 Coreswitch1 in Datacenter1
----2 Floorswitch1
------4 Roomswitch1a
------ 5 Roomswitch1b
----3 Floorswitch2
------ 6 Roomswitch2a
------ 7 Roomswitch2b

Now i have a PARENTID2 in my records, because all Floorswitches are additionaly connected to Coreswitch2 in datacenter2.
Example:
Floorswitch1 has PARENTID = 1 (connection to coreswitch1 in datacenter1) and PARENTID2 = 9 (connection to coreswitch2 in datacenter2)

I want to get a result like this:

root
–1 Coreswitch1 in Datacenter1
----2 Floorswitch1
------ 4 Roomswitch1a
------ 5 Roomswitch1b
----3 Floorswitch2
------ 6 Roomswitch2a
------ 7 Roomswitch2b
–9 Coreswitch2 in Datacenter2
----2 Floorswitch1
------ 4 Roomswitch1a
------ 5 Roomswitch1b
----3 Floorswitch2
------ 6 Roomswitch2a
------ 7 Roomswitch2b

Can this be done with the Servoy DBtreeview ???
If not, any other idear??

Any help welcomed
Best regards
Albert

hi Albert,

so, you have your table T1 (id, parent1_id, parent2_id);
you will have to create an additional table, T2(parent_id, child_id), that
will contains all the parent,child pairs, then define 2 relations :
nRelation (T1.id → T2.parent_id) and mRelation (T2.child_id->T1.id)
and set that relations on the dbtreeview, with : setNRelation and respective
setMRelation

regards

Hello Gaby
Thank you!
But!!
I ran into another problem.

Main table = ivnetz Key = ivnetzid(autoincrement)+ some fields+parentid+parentid2
Second table = ivnetzstruktur key = ivnetzstrukturid(autoincrement)+ parentid,childid
I set the ivnetzstrukturid to db_seq in the servoy table definition!
I filled the second table with the needed information.
The treeview shows the wanted structure now.

When i insert a record in ivnetz i have to do 1/2 additional inserts into ivnetzstruktur, but this doesn’t work ???
With controller.newrecord of form pflege_ivnetz i set vneuanlage to 1

Function save record in form pflege_ivnetz

function m_speichern() {
	
	geaendert = application.getServerTimeStamp();
	a_benutzer = globals.g_benutzer;
	databaseManager.saveData();
	
	//bei neuanlage daten in ivnetzstruktur speichern
	if (forms.Pflege_Netz.vneuanlage = 1)
	{
		
		//wenn parentid da
		if (parentid > 0)
		{
		
		var vins = "insert into ivnetzstruktur (parentid,childid,angelegt,geaendert,a_benutzer,g_benutzer) "+
		"values(?,?,?,?,?,?)";
		
		var args = new Array();
		args[0] = parentid;
		args[1] = ivnetzid;
		args[2] = application.getServerTimeStamp();
		args[3] = application.getServerTimeStamp();
		args[4] = "EDV";
		args[5] = "EDV";
		
		var done = plugins.rawSQL.executeSQL("pug_produktiv","IVNETZSTRUKTUR",vins, [args])	;
		var done1 = plugins.rawSQL.executeSQL("pug_produktiv","IVNETZSTRUKTUR","commit")	;
		
		}
		//wenn parentid2 da
		if (parentid2 > 0)
		{
		var vins = "insert into ivnetzstruktur (parentid,childid,angelegt,geaendert,a_benutzer,g_benutzer) "+
		"values(?,?,?,?,?,?)";
		
		var args1 = new Array();
		args1[0] = parentid2;
		args1[1] = ivnetzid;
		args1[2] = application.getServerTimeStamp();
		args1[3] = application.getServerTimeStamp();
		args1[4] = "EDV";
		args1[5] = "EDV";
		
		var done2 = plugins.rawSQL.executeSQL("pug_produktiv","IVNETZSTRUKTUR",vins, [args1])	;
		var done3 = plugins.rawSQL.executeSQL("pug_produktiv","IVNETZSTRUKTUR","commit")	;
		
		}
	}	
	
		
}

The record is inserted into IVNETZ, but not into IVNETZSTRUKTUR?
The variables(args(0) and args(1)) are OK
Done and done2 allways false !???

What do i miss?

Any help welcomed.

Best regards
Albert

it seems that in your first rawSQL, you put your arguments array into a new array, when you do this: [args]
btw, if the rawSQL returns false, you can get the error of the operation with : plugins.rawSQL.getException().getMessage()