Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

getField from related table when target field is empty

Featured Replies

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

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;

}

?>

  • Author

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

  • Author

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

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.