What if you use ```
if (!databaseManager.hasRecords(currentfoundset[relName]))
ADDITION :
I use the following construction when I need this kind of function (If I understand correctly what you are doing)
var _relName = ‘con_to_cfg’;
var _curIndex = foundset.getSelectedIndex()
var _record = foundset.getRecord(_curIndex)
if (!databaseManager.hasRecords(_record[_relName]))
{
application.output(‘has no records’);
}
else
{
application.output(‘has records’);
}
No, all I’m trying to do is get the relationship name - which I can do with foundset.getRelationName() that works fine.
However if I put that relationship name in a var such as
var relName = foundset.getRelationName() that works too (checking with app output to the console. But when I use that var in a databaseManager.hasRecords(relName) the var is not recognised as a relationship name.
I’m doing this so I can write some generic code and not need to hard code the relationship name every time.
Should be simple - so I’m guessing there is some way for format the var in the call to make it readable!
var $fs = myFoundset;
var $relation = 'myRelation';
var $result1 = databaseManager.hasRecords($fs, $relation);
var $result2 = databaseManager.hasRecords($fs[$relation]);
application.output($result1);
application.output($result2);
however: if the relation you’re testing is a global relation, then using a variable just don’t seem to work.
I tried different syntax for this (just [$relation]) but I can’t get the trick either.
var $relation = ‘myRelation’;
var $result1 = databaseManager.hasRecords($fs, $relation);
var $result2 = databaseManager.hasRecords($fs[$relation]);
application.output($result1);
application.output($result2);
however: if the relation you're testing is a global relation, then using a variable just don't seem to work.
I tried different syntax for this (just [$relation]) but I can't get the trick either.
Maybe it's a bug?
Well tested Marc - thanks - and yes it is a global relation in this instance. I’ll post it as a bug if I can recall how to (its been so long) ;-}
Some more info about the string, if you use it by name so relation name then hasRecords must have as the first parameter the record where that relations needs to be loaded from
so
hasRecords(foundset); // a relation is a foundset!
hasRecords(record, relationname);
What databaseManager.hasRecords() function is expecting as input parameter is a foundset and relations return a foundset.
In this case, you are passing as parameter a String (the name of the relation) not a foundset.
I hope this helps!
Thanks for that feedback Gerado - could you explain how I might make that relation name into an object for use in this way then? I’ve experimented with and other formats but this is strange behaviour indeed.
The example code (part of it) for this is : if databaseManager.hasRecords(orders_to_orderitems) so its obvious we can use a relation directly, but how should that relation be formated in a var to be usaeable.
I get the impression I’m eiether barking up the wrong tree (gone completely off track) or I’m just not making sense. Surely I can place a relasion into a variable and use it in hasRecords one way or another??? What am I missing here?
Johan - thanks for the feedback too but that really is not a help - can you give some guidance on how to get the relation name into the .hasRecords by means of a variable - using var x = foundset.getRelationName?? This really is necessary else everywhere we place this code will need to have the relation name hard coded??
(this ofcourse wont work if you did foundset.getRelationName() on the same foundset to get that relationname first! because then you ask for a relation record its own relations… so order_to_orderitems.orders_to_orderitems which is just wrong)
If you purely work with global relations that you want to test you can do: