4 Replies Latest reply on Jul 19, 2017 8:04 AM by mikebeargie

    FileMaker Pro Server 15 PHP API problem with getRelatedSet

    macgurunc

      Hi,

       

      I've had a solution that has worked for 2+ years on FileMaker Pro Server 12. After upgrading to FMS15 on our hosting provider the getRelatedSet PHP command does not appear to work anymore. No matter how many records are in the related table, it always returns the count as 1 and will not access the related data via getField('relatedTable::field').

       

      Anyone seen this issue?

        • 1. Re: FileMaker Pro Server 15 PHP API problem with getRelatedSet
          mikebeargie

          https://fmhelp.filemaker.com/docs/15/en/fms15_cwp_guide.pdf

           

          getField('relatedTable::field') when used outside of a specific context will only return one result, same as it does in filemaker.

           

          You haven't posted your code, so we really can't troubleshoot it.

           

          Does your call look like this?

          <?php
          $record
          = $fm->getRecordByID("LayoutName", $_GET['id']);
          $related_records = $record->getRelatedSet('related_data');
          foreach(
          $related_records as $related_record)
          {
          echo
          '<tr><td>' . $related_record->getField('related_data::Text') . '</td></tr>';
          }
          ?>
          • 2. Re: FileMaker Pro Server 15 PHP API problem with getRelatedSet
            macgurunc

            Hi Mike,

             

            Thanks for the reply. My code uses the same method you show - slightly modified on the echo to format as hyperlink but otherwise identical. My point is that the exact same code and database worked perfectly prior to the migration to FMS15. I am using a workaround now that replaces getRelatedSet with a search based on the foreign key used in the relationship between the two tables in question. I replicated the same environment on FMS14 and it worked so it appears the issue is tied to FMS15 or possibly the PHP environment on the hosting server. I continue to investigate and will report my findings.

            • 3. Re: FileMaker Pro Server 15 PHP API problem with getRelatedSet
              fpeaker

              I am having the same issue using the getRelatedSet() as macgurunc. I have tried a number of different related tables and in each case when using the PHP getRelatedSet, I continue to receive the following error:

               

              Fatal error: Call to undefined method FileMaker_Implementation::getField()

               

              // I have also tried the Jonathan Stark method of pulling in a layout as an object and looping through all the portals and grabbing the related tables, which still does not work.

               

              Here is the code:

              <?php

                      // Search FM data for Contact details based on username/pw     

                      $findCommand =& $fm->newFindCommand($layoutName);  

                      $findCommand->addFindCriterion('WebsiteUsername', $username);

                      $findCommand->addFindCriterion('WebsitePassword', $password);

                      $result = $findCommand->execute();

               

                       if (FileMaker::isError($result)) {

                         echo 'unable to find the user records: ' . $result->message . '(' . $result->code . ')';

                         die();

                      }

               

                      $records = $result->getRecords();

                      $recordId = $records[0]->getRecordId();

                      $storedUsername = $records[0]->getField('WebsiteUsername');

                      $storedPassword = $records[0]->getField('WebsitePassword');

                      $address1 = $records[0]->getField('BAddress1');

                      $address2 = $records[0]->getField('BAddress2');

                      $city = $records[0]->getField('BCity');

                      $state = $records[0]->getField('BState');

                      $zip = $records[0]->getField('BZip');

                      $primaryEmail = $records[0]->getField('EmailPrimary');

                      $phoneMobile = $records[0]->getField('PhoneMobile');

               

                      $record = $fm->getRecordByID($layoutName, $recordId);

                      $related_records = $record->getRelatedSet('CON');

                      foreach($related_records as $related_record)

                      {

                       echo '<tr><td>' . $related_record->getField('CON::Stripe.CustObjectID') . '</td></tr>';

                      }

               

              Any help will be greatly appreciated.

              • 4. Re: FileMaker Pro Server 15 PHP API problem with getRelatedSet
                mikebeargie

                What version of PHP are you running on your server?

                 

                If it's PHP 5.5+, you may want to use this package:

                GitHub - airmoi/FileMaker: FileMaker PHP API rewrited for PHP 5.5+

                 

                Which has some of the reference issues in the older code of the PHP API corrected.

                 

                On the page above, it demonstrates a more modern style of using a class:

                use airmoi\FileMaker\FileMaker;

                use airmoi\FileMaker\FileMakerException;

                require('/path/to/autoloader.php');
                $fm = new FileMaker('database', 'localhost', 'filemaker', 'filemaker', ['prevalidate' => true]);

                And also forming your request in a proper error trapping Try/Catch operation:

                try {

                   $command = $fm->newFindCommand('layout_name');

                   $records = $command->execute()->getRecords();

                  

                   foreach($records as $record) {

                   echo $record->getField('fieldname');

                   ...

                  }

                }

                catch (FileMakerException $e) {

                   echo 'An error occured ' . $e->getMessage() . ' - Code : ' . $e->getCode();

                }

                 

                In your code you posted, you are never error checking $related_records, so if you comment out your last foreach loop, and instead dump out $related_records to the screen:

                echo "<pre>";

                print_r($related_records);

                echo "</pre>";

                you may find something in the $related_records data that tips you off to an issue.

                 

                 

                Also, at the top of your PHP script you can have it dump all errors out to screen:

                ini_set('display_errors', 1);
                ini_set
                ('display_startup_errors', 1);
                error_reporting
                (E_ALL);

                Try that to see if any other errors are occurring that might be messing with the output.