I have quite some tables in my database, a lot of them contain about 15 ‘basefields’ (ie. creation date, creation user, etc.)
In previous versions of Servoy I had no problems at all checking if a dataprovider existed doing something like this:
forms[$form]['fieldnameToCheck']
In 4.0.1 every attempt just returns a ‘null’ value, no matter whether a dataprovider exists or not.
This way it’s gonna be hard to determine the difference between an ‘emtpy’ dataprovider or a non-existing one…
Does anyone have a solution for this, maybe I’m just using the wrong syntax. But as I am not (yet) a javascript guru I might oversee some basics…
I’m not seeing the behavior you describe in 4.0.1. How exactly are you testing the value?
// test a valid dataprovider
application.output( forms['formName']['this_does_not_exist'] ); // undefined
// test an invalid dataprovider
application.output( forms['formName']['this_does_exist'] ); // value of 'this_does_exist' -- which could be null
As Paul points out, however, this is a test for any property on the form and doesn’t tell you whether the specific property is a dataprovider or not.
just tested the codes you mentioned: in 4.0.1 you won’t notice the behaviour, intermediate build 4.0.1i6 (which addressed some of the issues I had in 4.0.1) seems to be the one that is bugging me now in this case.
Using gregs (and my initial) code, everything I try will return ‘null’ > Pauls code returns ‘false’.
Anyway: I’m thinking to move back to 4.0.1, i6 is very slow and has some more (major)bugs that are getting in my way.
I understand the restraints about testing on properties rather than testing a dataprovider.
To make sure that a table has a certain column, I wrote the included method. This methods aquires a formname and a column name and will check for you if the table connected to the form has that column.
var _form = arguments[0]
var _column_name = arguments[1].toLowerCase()
var _table = forms[_form].controller.getTableName()
var _jstable = databaseManager.getTable(currentcontroller.getServerName(),_table);
var _columns = _jstable.getColumnNames()
for ( var i = 0 ; i < _columns.length ; i++ )
{
if( _columns[i].toLowerCase() == _column_name)
{
return true;
}
}
return false