Passing Arrays from one method to another.

In MethodA I have the following code. The first array is PKs, the second is a text string, typically something like “L1,L2,L3”.

var comArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'company_id');
var keys = new Array(globals.gtext);
forms.catitemUtility.MethodB(comArray, keys);

Here’s MethodB’s code:

var comArray = arguments[0];
var comArrayLength = comArray.length;
application.output('comArray = ' + comArray)
// returns in the form of [1,2,3]
application.output('comArrayLength = ' + comArrayLength);
// returns the correct number of array elements.
var keys = arguments[1];
var keysLength = keys.length;
application.output('keys = ' + keys)
// returns in the form of "L1,L2,L3", NO square brackets
application.output('keyLength = ' + keyLength);
// ALWAYS returns "1.0", the INCORRECT number of elements

I don’t understand why the “keys” array (if it is indeed an array) is behaving differently from the comArray of integer PKs. I need to loop through the elements of the “keys” array.

Morley:
I
I don’t understand why the “keys” array (if it is indeed an array) is behaving differently from the comArray of integer PKs. I need to loop through the elements of the “keys” array.

I do not think your variable “keys” is an array!!!.
To store and retrive an array in a global variable I think you must use some workaround.
“L1,L2,L3” is not an array, it is simply a character string with some commas in it.
Anyway should be easy to check out what keys is and contains with the debugger :wink:

automazione:
I do not think your variable “keys” is an array!!!.

You’re quite correct. Johan has pointed out the following code will generate a text array from a string.

var a = 'red,white,blue';
var b = a.split(',');

“b” is a properly formed array with three elements. In this state I can now probe it for its length, loop through its elements, pop its last element, and so forth.