var comArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'company_id');
var newArray = new Array();
for ( var i = 0 ; i < comArray.length ; i++ )
{
newArray[i] = comArray[i];
}
var clientIDsToQuery = newArray.toString();
It remains an interesting question why myArray.toString() does not lead to the same result.
I have had a similar problem once and figured out, that the resulting array is a javaarray and not a Javasript-Array. With a javaarray some Array functions just don’t work as expected in JavaScript, like splice. But obviously, getFoundSetDataProviderAsArray doesn’t return a Javascript Array.
The first question is.. Why do you need to convert a array to that string of a sql query??
That shouldn’t be done anyway because i think you want to do this:
String sql = “select x from y where z in (” + array.join(‘,’) + “)”;
databasemanager.getDatasetByQuery(sql);
yes?
you should do:
String sql = “select x from y where z in (?,?,?)”;
databasemanager.getDatasetByQuery(sql,array);
and then have the same number of ? in as the size of the array.
jcompagner:
String sql = “select x from y where z in (” + array.join(‘,’) + “)”;
databasemanager.getDatasetByQuery(sql);
You should do:
String sql = “select x from y where z in (?,?,?)”;
databasemanager.getDatasetByQuery(sql,array);
and then have the same number of ? in as the size of the array.
Could you clarify why the latter is preferable to the former? Note that the number of elements in the array will be unknown.
Trying to get my mind around working with arrays in Servoy.
I have a method that finds the groups a user is a member of and stores them in an array…I store the array as string into a global so I can use it later in a different method.
method #1
var arrayGroups = new Array();
var arrayGroups = databaseManager.getFoundSetDataProviderAsArray(foundset,‘group_id’);
globals.gGroupString = arrayGroups.join(', ');
Then in another method I want to put the array as string stored in the global above into a text field:
I would expect ‘groups_array’ to display something like ‘45,32, 12’ but instead I get this:
java.lang.Object@a27a33/n java.lang.Object@a27a33/n java.lang.Object@a27a33/n java.lang.Object@a27a33/n java.lang.Object@a27a33
I am obviously misunderstanding something here. Thanks for any help on this.
Arrays returned by database manager functions are different than arrays that you create yourself. This is distinctly highlighted when you view the array variables in the debugger when running the following code:
//this returns "[7,8]"
var array = databaseManager.getFoundSetDataProviderAsArray(foundset,'id_main');
//this returns "7,8"
var x = new Array('7','8');
So the extra brackets create a problem. Convert the “bracketed” array to a “javascript” array and then your array will behave as you expect. Here is a snipet of code where I first return the “bracketed” array then loop through it and load a “javascript” array:
//get fm field names
var server = controller.getServerName();
var maxRows = forms.lvl1_bridge_detail.bridge_to_fmfield.getSize();
var FMFieldsQuery = 'select f_name from fmsql_fmfield where id_bridge = ' + globals.select_bridge + 'order by f_order;';
var FMFieldsDataset = databaseManager.getDataSetByQuery(server, FMFieldsQuery, null, maxRows);
var tempARY = FMFieldsDataset.getColumnAsArray(1);
var FMFieldsARY = new Array;
for (var a in tempARY)
{
FMFieldsARY[a] = tempARY[a];
}
Would be nice to get these two array forms standardized.
what do you mean this returns “xxx” ?
How does it return what code do you use to convert that array back into a string? The split function?
Please give a complete example so that i can see if i can make it the same
My first code snippet is complete. Run it with the debugger on and you will see that the values of the two arrays are displayed differently. The first one has brackets around the values and the second one doesn’t.
In my situation I’m not using the array in a sql query so not sure if there is a problem with converting to a string. My problem comes from passing arrays to a custom plugin. My plugin doesn’t accept the “bracketed” array form so I first have to convert it to a “javascript” array before sending it to my plugin.
My plugin is defined to accept that value as String variable. I bring this up in this thread to highlight that there are two forms of arrays in the Servoy method editor. Not sure if they behave differently with other functions (such as the standard array functions or loading a value list, etc). I would have to test further. But as usual, I fixed my problem and moved on
ok. i think i know why it doesn’t work
That is because the first is a Object not a String so if you made youre plugin so that it supports Object then it would work.
I think the native javascript array is just trying to convert to the right type for you when calling. I will try to fix it that als a native java object tries to do that.