Hi,
I developped a module where the user can select all database servers, then all related tables, and finally all related columns, using some custom SQL queries on the repository server and an (empty) custom dynamic drop-down list.
function getServerNames()
{
//Get a dataset based on query
var maxReturnedRows = 10000;//useful to limit number of rows
var vQuery = 'SELECT connection_name FROM servoy_columninfo';
var vArgs = null;
var vDataset = databaseManager.getDataSetByQuery('repository_server', vQuery, vArgs, maxReturnedRows);
// Return new array with duplicate values removed
var a = [];
var d = vDataset.getColumnAsArray(1);
var l = d.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
// If d[i] is found later in the array
if (d[i] === d[j])
j = ++i;
}
a.push(d[i]);
}
vDataset = a;
// Remove repository_server from list
for (var i=0; i<vDataset.length; i++ ){
if (vDataset[i]=="repository_server")
vDataset.splice(i,1,"");
}
application.setValueListItems( 'dyn_vl', vDataset.sort());
The code works fine if I run it as a solution, but not when it is run from within a module of another solution. Does anybody know why this is?
On a related note, can anyone tell me how to get an array of all forms related to a particular solution table, using a similar query on the repository as the one above?
Thanks in advance,
Ben
i dont see any reason why that code wouldnt run in a module
What happens what error do you get?
In servoy 5.0 you get support to get forms based on a datasource string or server/table combo through the solution model.
Doing that by querying the repo tables is not really supported by us and can break at any time.
You should look at the databaseManager node (getServerNames() for example ) and solutionModel node to do the stuff you do
Johan,
Forgot to mention I was running v4.1.4.
I don’t see any reason why it shouldn’t work either. No errors pop up, it’s just that the dynamic valuelist isn’t showing anything. If I run the following code with an onFocusGained method:
var vList = databaseManager.getServerNames();
application.setValueListItems( 'dyn_vl', vList);
my variable gets populated, but the ‘dyn_vl’ custom valuelist does not get the array when run as a module, but works fine when run as solution. Could this have something to do with my valuelist being tied to the module, and not to the main solution? Even if I wanted to attach a dynamic VL from the main solution to the first field of the module’s form, it’s not being ‘seen’ from the module, so I can’t do that either… ![Crying or Very sad :cry:]()
You’re right about avoiding to query the repository (will you tell us when it actually breaks, please?) and using the solutionModel instead. I was just trying to get this to work using any other way, but I’m back to square 1.
Speaking of the solutionModel, I notice there are functions to get the list of all medias, valuelists, relations, global methods and global variables for the current solution, but not for getting all form names - could this be an oversight? Under the global nodes, there is already an option for ‘allrelations’, ‘allvariables’, ‘allmethods’, and there is also ‘Forms.allnames’, but this one does seem to have made the cut to the solutionModel…
Thanks in advance,
Ben
you are filling a the valuelist in an onfocusgained of a field that has that valuelist as its valuelist?
Dont think that will work in all situations.
What happens if you just fill it before you show that field at all? So in the onShow of the form or solution?
There is no difference at runtime between modules and solutions. They are seen as 1 big thing.
In servoy 5.0 you will have getforms()
First thought is always, why do you need all the forms? Because getting 1 form to change it is very logical
But what do you want to do with all the forms?
You are right, Johan, it works better if I set the valuelist items of my first valuelist using an onshow method, otherwise the display size of the valuelist stays stuck to the size of the previous one. However, this is still not working when I set the solution as a module!!! ![Crying or Very sad :cry:]()
Any other ideas?
What I’m trying to do is to modify my CSV Importer Module to be able to specify a database server, a table, a column and a form (all related to each other) to make the process more user-friendly.
Thanks in advance,
Ben
i dont know why it wouldnt work as a module there is or there shouldnt be any different behavior for that.
make a case where you see this with a solution and a module.