hasRecords() does not work with a variable as Relationship?

This code does not work when using a relation name in a variable

elements.lbl_empty_record.visible = false
	var relName = foundset.getRelationName();
	if (!databaseManager.hasRecords(relName)){elements.lbl_empty_record.visible = true}
	application.output(relName)

The app output is correct and shows the relation name.

But does with a the full relation stated:

elements.lbl_empty_record.visible = false
	var relName = foundset.getRelationName();
	if (!databaseManager.hasRecords(gcomponent_detail_to_corrosion_condition)){elements.lbl_empty_record.visible = true}
	application.output(relName)

Have I missed the point on some formatting I need to make the var readable in the hasRecords function?

Hi Ian,

I am not sure what you want to do here.

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’);
}


Regards,

Thanks for the feedback Hans

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!

Hi Ian,

tested a bit and both methods below do work:

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.

Maybe it’s a bug?

mboegem:
Hi Ian,

tested a bit and both methods below do work:

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.

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) ;-}

Posted Case 311811

first of all this:

var $result1 = databaseManager.hasRecords($fs, $relation);

does NOT test your relation! But does test if your $fs has records!

just look at the docs, the first param kan be a foundset or a record, if it is a record then the second param will be used to lookup the relation.

The second param is not used if the first param is not a record.

also the thing from the pure global relation i can’t reproduce if i do this:

	application.output(foundset["global_to_order_details"].getSize());
	application.output(databaseManager.hasRecords(foundset["global_to_order_details"]));

then my output is

17
true

jcompagner:
also the thing from the pure global relation i can’t reproduce if i do this:

which version do you use?
I used the exact same syntax this morning in v5.1.4 and got ‘false’ returned…

Perhaps I’m being dumb here Johan (and thanks for the rapid feedback BTW) but why does this work:

if (!databaseManager.hasRecords(gcomponent_detail_to_corrosion_condition))

and this does not

var relName = foundset.getRelationName(); //== gcomponent_detail_to_corrosion_condition is a global relation
if (!databaseManager.hasRecords(relName))

My point is that when using a var to reference the relation name the .hasRecords(var) does not return as expected.

Hi!

Kahuna:
Perhaps I’m being dumb here Johan (and thanks for the rapid feedback BTW) but why does this work:

if (!databaseManager.hasRecords(gcomponent_detail_to_corrosion_condition))

What databaseManager.hasRecords() function is expecting as input parameter is a foundset and relations return a foundset.

Kahuna:
and this does not

var relName = foundset.getRelationName(); //== gcomponent_detail_to_corrosion_condition is a global relation

if (!databaseManager.hasRecords(relName))




My point is that when using a var to reference the relation name the .hasRecords(var) does not return as expected.

In this case, you are passing as parameter a String (the name of the relation) not a foundset.

I hope this helps!

i am using 5.2

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);

those 2 work.

gerardo.gomez:
Hi!

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??

but why do you do:

var relationName = foundset.getRelationName()

and then

databaseManager.hasRecords(relationName)

what is the use case for that?

because the shortcut is just:

databaseManager.hasRecords(foundset)

if you have just the relationname and you want to test this you have to have a record to test on.

databaseManager.hasRecords(foundset.getSelectedRecord(), relationname)

(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:

databaseManager.hasRecords(globals[relationname])

Thanks Johan - once again over thinking things process - thanks for the clarity - and to all others who chimed in too.