help assignin customer_id to same data for each customer

I have one table that each customer uses but has the ability to customize for their own. I need to pull the same data in for each customer to start with.

I have a function to import legacyData into a new table that currently is only for 1 customer - works great but I need to do this individually for each customer.
I created another function that will call the first function and assign a customer id to each set of data - but it’s only assigning 1 customer id to the first record but it is importing for each customer?

What I have so far is:

function tentants(){
	/** @type {JSFoundset<db:/data/tenants>}*/
	var tenants = databaseManager.getFoundSet('data','tenants');	
	tenants.loadAllRecords();

			/** @type {JSFoundset<db:/data/text>}*/
	var records = databaseManager.getFoundSet('data','text');
	records.loadAllRecords();
	
		for(var t = 1; t <=tenants.getSize(); t++){
			migrateNtext()
			records.tenant_id = tenants.tenant_id;

	}
		databaseManager.saveData();
}

the migrateNtext() works fine for one customer at a time, but I don’t really want to do this individually for all my customers. Any helpful tips?

Thanks in advance

You loop through the number of records, but you don’t change which record you are performing the operation on. You need to loop through one or both of the foundsets. ( I am not sure which as I am not exactly clear on what you are trying to do) : part of your code re-written is below.

var currentTenant ;
for(var t = 1; t <=tenants.getSize(); t++){
currentTenant = tenants.getrecord(t) ;
migrateNtext() ;
records.tenant_id = currentTenant.tenant_id;
   }

You can get the idea behind this, though all it does is repeatedly set the tenant_id for the first record in the foundset records to the respective tanant record. Probably not what you want. But should get you pointed in right direction.

Again, although I am not quite clear on what you want to end up with, you may want to look at the foundsetUpdater function. It changes one field’s value in a whole foundset so all are the same value, and does it very efficiently. Here it is per the wiki http://wiki.servoy.com/display/public/DOCS/JSFoundSetUpdater

//1) update entire foundset
var fsUpdater = databaseManager.getFoundSetUpdater(foundset)
fsUpdater.setColumn('customer_type',1)
fsUpdater.setColumn('my_flag',0)
fsUpdater.performUpdate()

Matt, Thanks for the tip. I’ll let you know how it goes, but let me try to clarify what I’m doing.

I’m importing a table that is a set of records that each tenant will start their product with. This is a standard set of records that everyone needs access to individually because they have the option of customizing each record specific for themselves.
So I guess what I’m trying to do is iterate over both this legacy text file and the tenants table to assign each set of legacy text to each tenant linked by tenant_id.

Bob

Thanks again Matt,

You lead me in the right direction, but I needed to put this code in the migrateNtext() function so it would assign the ID’s properly.

Bob