getFoundSetDataProviderAsArray question

When the user clicks the OK button on a FormInDialogue I need to capture as an array the current foundset of the originating form (lying behind the FormInDialogue).

I’ve tried:

var comArray = databaseManager.getFoundSetDataProviderAsArray(forms.comDetails.foundset,'company_id');

However it produces this result:

[Ljava.lang.Object;@948cba

I’ve also tried loading the FormInDialogue with the same records (successful in that). However:

	var comArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'company_id');

generates this error:

[Ljava.lang.Object;@f12c21

Is there an available syntax to accomplish my purpose?

Version R2 2.1.2-build 315
Java version 1.4.2_06-b03 (Windows XP)

Morley:
I’ve tried:

var comArray = databaseManager.getFoundSetDataProviderAsArray(forms.comDetails.foundset,'company_id');

However it produces this result:

[Ljava.lang.Object;@948cba

How do you look at that result…through Application.output() ?
That shows only strings (and numbers). Objects like arrays are shown as object references.
You can test it yourself:

var myArray = [1,2,3,4,5];

application.output(myArray);

Morley:
I’ve also tried loading the FormInDialogue with the same records (successful in that). However:

	var comArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'company_id');

generates this error:

[Ljava.lang.Object;@f12c21

I don’t think you’ve got an error.
I think you are misinterpreting the result.

That’s what I did.

var comArray = databaseManager.getFoundSetDataProviderAsArray(forms.comDetails.foundset,'company_id');
application.output(comArray);

Which produces

[Ljava.lang.Object;@948cba

Produces [1,2,3] when the form is displayed in the standard fashion but otherwise when within a FormInDialogue.

Morley:

var comArray = databaseManager.getFoundSetDataProviderAsArray(forms.comDetails.foundset,'company_id');

application.output(comArray);



Which produces 

> [Ljava.lang.Object;@948cba

Produces [1,2,3] when the form is displayed in the standard fashion but otherwise when within a FormInDialogue.

Produces [1,2.3] how?

If you try to display the array object it should show the object reference in both cases.

try:

application.output(comArray[1])

..and your output will give you a readable value (assuming there are values inside your array)

in other words you would have to loop through the array object in order to see it’s values.

TIP: also use the variables TAB , and step through your script in order to check content of objects like arrays.

maarten:
try:

application.output(comArray[1])

..and your output will give you a readable value (assuming there are values inside your array)

in other words you would have to loop through the array object in order to see it’s values.

TIP: also use the variables TAB , and step through your script in order to check content of objects like arrays.

Now I’m REALLY confused. I’ve been using databaseManager.getFoundSetDataProviderAsArray for about a month and have never had any problems with it before. Testing with application.output(arrayName) has always returned a [1,2,3] type of result. That is, until I tried to use it within a FormInDialogue situation when I started to get this weird “[Ljava.lang.Object;@” response.

While waiting for some feedback to this thread I went ahead and created a small testing solution and, get this, this one ALSO produced gibberish with application.output(arrayName). This time I didn’t get as far as trying it in a FormInDialogue situation. This gibberish turned up with a standard form. It also put “companyid (the name of the field requested for the array) INTEGER NOT NULL” in the lower left corner of the methods editor. Identical code, nothing different. No idea why it was telling me that. No idea why it isn’t telling me this in my main solution. In both situations the companyid field is the pk and both are integer fields.

Picking up now on Maarten’s recommendation of using application.output(arrayName[1]) I get yet a different form of response. It says “11.0”. What’s this mean? It’s definitely NOT the number of elements in the array. That number is considerably higher.

By the way, I also checked the Variables section of the debugger. It DOES list the required field elements in the array. It would now appear I’ve been getting a false positive for an error because I was relying on application.output(arrayName) to give me consistent feedback.

I want to understand what’s going on here. What’s this “[Ljava.lang.Object;@” stuff all about? Why does application.output(nameArray) sometimes output in the form [1,2,3] and sometimes as “[Ljava.lang.Object;@”? And what is the meaning of application.output(arrayName[1]) producing an answer of “11.0”?

I need to know so I can have a surer understanding of the ground I’m standing on. Thanks.

Morley:
Now I’m REALLY confused. I’ve been using databaseManager.getFoundSetDataProviderAsArray for about a month and have never had any problems with it before. Testing with application.output(arrayName) has always returned a [1,2,3] type of result. That is, until I tried to use it within a FormInDialogue situation when I started to get this weird “[Ljava.lang.Object;@” response.

Morley:
Picking up now on Maarten’s recommendation of using application.output(arrayName[1]) I get yet a different form of response. It says “11.0”. What’s this mean? It’s definitely NOT the number of elements in the array. That number is considerably higher.

By the way, I also checked the Variables section of the debugger. It DOES list the required field elements in the array. It would now appear I’ve been getting a false positive for an error because I was relying on application.output(arrayName) to give me consistent feedback.

I want to understand what’s going on here. What’s this “[Ljava.lang.Object;@” stuff all about? Why does application.output(nameArray) sometimes output in the form [1,2,3] and sometimes as “[Ljava.lang.Object;@”? And what is the meaning of application.output(arrayName[1]) producing an answer of “11.0”?

I need to know so I can have a surer understanding of the ground I’m standing on. Thanks.

I can’t tell you why you get a [1,2,3] result back when you should get [Ljava.lang.Object;@etc. back.
Again…when you use application.output() you get the OBJECT back.

Yes you can DEFINE an array with arrays using [1,2,3] but as you can see it’s not a string. JavaScript turns it into an Array Object.

To read data out of an Array you need to tell it from what position in the array you want the data. This is what Maarten was talking about.
arrayName[1] means ‘give me the value in the array at the second position’ (Array’s are zero based).
So yes you can get a value 11.0. It means that the Array contained that value (eleven) in position 1 (second position in the array).

To make it more visible, here an example:

var myArray = [10,11,12];

application.ouput(myArray[0]);

→ 10.0

application.ouput(myArray[1]);

→ 11.0

application.ouput(myArray[2]);

→ 12.0

application.ouput(myArray[3]);

→ null

As you can see myArray[3] returns a null. Why? Because the array is not that long, there is no value at position 3 (fourth position in the array).

And like Maarten said. You can use the debugger to view variables (Variables tab).
Just make sure you enable the debugger, place a break right after the variable and run the method.
It instantly shows the variables and their values in the variables tab.

I hope this brief Array/Debugger primer helps you on your way.

Until very recently I’ve been getting a response to application.output(arrayName) in the form of [1,2,3], very consistently, all occasions. I’ve been assuming that’s the norm.

Therefore my confusion when “[Ljava.lang.Object;@” started to turn up on some occasions, not on others. Still don’t understand why the inconsistency, but no matter. I should be monitoring the Variables tab instead of using application.output().

Thanks for the explanation Bob.