Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4989 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi,

I'm trying to understand why I get thrown an error when pointing a getField to an empty field in a related table. Empty fields in the main table simply show up as...well, empty, when a getField is used to echo their content.

Example:

<?php $relatedSet = $record->getRelatedSet('taxontable');

foreach ($relatedSet as $relatedRow)

{

$relatedSet = $relatedRow->getField('taxontable::taxon');

echo $relatedSet;

}

?>

In this case, "taxontable::taxon" is a field in a related table, accessible to me through a portal on the layout I'm using. There is no fault with the connection, I have no problems getting the contents of non-empty fields in related tables. However, an empty "taxontable::taxon" gives me a fatal "Call to undefined method::getField()" error. getField on an empty field in the main table does not give an error.

Any ideas?

Thanks a lot,

/daniel

Posted

Try adding some error checking code. My guess is that $relatedRow is an error object when you are trying to use getField...

also, try not using the same variable name in the foreach loop; it's confusing and it might be causing your error (I changed $relatedSet to $relatedField in the code below)


<?php

$relatedSet = $record->getRelatedSet('taxontable');

if( FileMaker::isError($relatedSet) ) echo $relatedSet->getMessage();



foreach ($relatedSet as $relatedRow)

{

	$relatedField = $relatedRow->getField('taxontable::taxon');

	if( FileMaker::isError($relatedField) ) echo $relatedField->getMessage();

	echo $relatedField;

}

?>

Posted

Using the code you suggested, I get a 'Related set "taxontable" not present.' message. The actual fatal error (Call to undefined method::getField()) is reported for the line containing

$relatedField = $relatedRow->getField('taxontable::taxon');

This makes sense to me. I now also see why there is a difference between an empty field in the main table and an empty field in a portal.

Since the error is not thrown until getField is called, I tried wrapping the error-producing code in an if-statement, but this did not work:

<?php

$relatedSet = $record->getRelatedSet('taxontable');

if (isset ($relatedSet)) {

foreach ($relatedSet as $relatedRow)

{

$relatedField = $relatedRow->getField('taxontable::taxon');

echo $relatedField;

}}

?>

Same error is reported, for the getField row. Any suggestions?

Thanks for the input,

/daniel

Posted

Problem solved,

I used the presence or absence of an error in the if statement:

<?php

$relatedSet = $record->getRelatedSet('taxontable');

if (!FileMaker::iserror ($relatedSet)) {

foreach ($relatedSet as $relatedRow)

{

$relatedField = $relatedRow->getField('taxontable::taxon');

echo $relatedField;

}}

?>

and this seems to have worked.

Again, thanks for the input!

Thumbs up,

/daniel

This topic is 4989 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.