store a related foundset for later insertion

Hi,

I’ve been messing around with record objects after Karel’s nice article in David’s magazine. In a nutshell I want the user to be able to grab the individual patient data stored in various tables on one database and insert that data in another. The tables and relations are not identical so I was planning on first using record objects to temporarily store the patient data from the ‘upload’ tables in global variables. Then use that data in the globals to insert the appropriate data in the ‘destination’ tables.

I know I could do this with queries/datasets but I’d like to get better with record objects and arrays (of arrays). When there is just one row from a table, I have no problem. And if I was looping through a foundset and immediately inserting those records/rows in another table/dataset on each ‘pass’ that also is clear. But when I want to store a related foundset in a global variable to be able to loop back later through that foundset I’m a little lost.

Doing this:

for ( var i = 0; i < forms.surgpath_case.ipox_results_to_lymphoma_codes.getSize(); i++ )
	{
		globals.myVar = globals.myVar + forms.parentTable.parentTable_to_relatedTable.getRecord(i + 1)
	}

does return the data in the global but I’m not sure how to access it. Do I need to have a particular separator between rows returned in the for loop?

Playing around I also tried this:

globals.myVar = forms.parentTable.parentTable_to_relatedTable.foundset

Which returned the following:```
4.7845; 4.7846;

The decimal numbers are the actual PKs for the two related records in the foundset. I have no idea what the number '4' is though nor how those could be used. But it looks kind of interesting!:)

Any help greatly appreciated!

Hi John,

john.allen:
Doing this:

for ( var i = 0; i < forms.surgpath_case.ipox_results_to_lymphoma_codes.getSize(); i++ )
{
	globals.myVar = globals.myVar + forms.parentTable.parentTable_to_relatedTable.getRecord(i + 1)
}


does return the data in the global but I'm not sure how to access it. Do I need to have a particular separator between rows returned in the for loop?

Since getRecord() returns a record object I suggest you put those objects in an array.

john.allen:
Playing around I also tried this:

globals.myVar = forms.parentTable.parentTable_to_relatedTable.foundset

Which returned the following:```
4.7845; 4.7846;

The decimal numbers are the actual PKs for the two related records in the foundset. I have no idea what the number '4' is though nor how those could be used. But it looks kind of interesting!:)

Not sure what the 4 is, maybe the parent PK of the relation ?

Hope this helps.

Hi Robert,

Thanks for the reply (but bedtime for you!).

Since getRecord() returns a record object I suggest you put those objects in an array.

That’s then an array (columns) of an array (rows) though right? But I’m not sure how to store/load those in my global variable and then how to extract them for inserting. The whole difference between a dataset, a record object and an array (and especially array of an array) is still somewhat fuzzy for me so I always end up working with datasets because those are more second nature to me. But do you mind pointing me in the right direction for loading multiple rows/objects in my global variable and then accessing them from there? What needs to be the separator between arrays(rows) so that I can loop through the records/rows in my global variable? And can the column values in the ‘column’ array be accessed the same way as a record object, i.e. with their actual database name like in Karel’s examples?

Not sure what the 4 is, maybe the parent PK of the relation ?

No I don’t think it’s that. But mentioning that makes me think it might be the Servoy number/id of the relationship.

john.allen:
Thanks for the reply (but bedtime for you!).

I am in the states right now, its after 9pm here, no bedtime yet for me ;)

john.allen:

Since getRecord() returns a record object I suggest you put those objects in an array.

That’s then an array (columns) of an array (rows) though right? But I’m not sure how to store/load those in my global variable and then how to extract them for inserting. The whole difference between a dataset, a record object and an array (and especially array of an array) is still somewhat fuzzy for me so I always end up working with datasets because those are more second nature to me. But do you mind pointing me in the right direction for loading multiple rows/objects in my global variable and then accessing them from there? What needs to be the separator between arrays(rows) so that I can loop through the records/rows in my global variable? And can the column values in the ‘column’ array be accessed the same way as a record object, i.e. with their actual database name like in Karel’s examples?

First of you need to realize that getRecord() returns a record object. So that is 1 row of your table.
So in a sense this object is an array in itself. A list of data if you will.
Now if you want to store multiple record objects in a variable you need to do that in an array.

Just imagine an array as a spreadsheet with 1 column (they can have multiple columns though but lets focus on 1 column) and multiple rows (or the other way around, doesn’t matter). Each cell of this spreadsheet can hold any kind of data (date/number/text). Same with an array.
It’s a list of data.

Also a record object only holds a pointer to your record (the PK). If you want to get/set the data it fetches/sets it on demand. Just how foundsets work.

recObject.myColumnName = "hi";

Now with a DataSet you actually have all that data fetched already so that can be more costly in some cases.

Also note that Karel’s article saves only 1 record object so you can use a global for that. When you want to save multiple record objects you always end up using an array. And yes you can store arrays in globals (type MEDIA) or use a undeclared variable (java script global variable).

globals.myVar  = new Array();
globals.myVar.push(foundset.getRecord(i));

And you can loop through them again like so:

for ( var i = 0 ; i < globals.myVar.length ; i++ )
{
	// address using following syntax:
	// globals.myVar[i].myColumnName 
}

Hope this helps.

Perfect! Glad you’re over here so you were up! I wasn’t sure what the syntax was for ‘pushing’ the rows/records when there were multiple rows but, duh, one treats each row/record array as simply another element of the ‘master’ array that can be simply pushed/unshifted on to it. I was all caught up in the ‘visualization’ of the array of the array, worrying about the separator between elements of the ‘big’ array versus the separator of the elements instead of just thinking about it as it is, simply an element of the array. And then the other thing that was bothering me as mentioned was whether I could address the elements (columns) in the same way as a record object when extracting them. And from your code it’s clear you can.

for ( var i = 0 ; i < globals.myVar.length ; i++ )
{
   // address using following syntax:
   // globals.myVar[i].myColumnName
}

I guess in other words when dealing with a record object one is essentially dealing with ‘named’ variables and likewise here, with the ‘names’ being the column names in both cases. Thanks a lot Robert!