4 Replies Latest reply on Nov 1, 2012 3:14 PM by rhowe

    PHP getValueListTwoFields with a record ID

    rhowe

      A question similar to this was asked about a year and a half ago by someone else, but there were no responses. Since I have come across the same problem, I'm asking it again:

       

      Setup: My database has a dynamic value lists -- it changes based on values in a record's field. It works fine in FMP; going record to record the value list changes appropriately.

       

      In PHP, I'm using getValueListTwoFields ('my-value-list-name-here', $my-record-ID). As in the long-ago post, I echo back the record ID to verify that it's correct. Nevertheless, the value list that I get back is the one from the first record.

       

      I've checked the web user privilege set, even going to far as to give the web user full access, without success. I'm at a dead end on what to look for next.

       

      ****

      Here's the relevant PHP code, with comments on what I'm doing:

       

      // I'm creating an audit-trail style record to track edits. In the New_Edits layout, passing a participant-id will populate all the relevant fields (via auto-enter relationships) from the main record. The database properly fills out all the fields.

      $rec = $fm->createRecord ('New_Edits');

      $rec->setField ('Participant_ID', $clean['Participant_ID']);

      $result = $rec->commit();

      ExitOnError($result);

       

      // so, at this point, we have a populated record. Here I get the record ID and echo it back to the web page, and it does indeed match the record ID I display on the layout.

       

      $rec_ID = $rec->getRecordId();

      echo "Rec ID = " . $rec_ID . "<br />";

       

      // So: for this record, the participant is in a particular program. The program operates in several districts. My value list presents the districts for a program, and naturally the value list differs based on what the program is.

      // I build the value list by getting the layout object, and passing the value list and the record ID to getvaluelisttwofields:

       

      $layout = $fm->getLayout('New_Edits');

      $District_Options = $layout->getValueListTwoFields('all_dists_for_program',$rec_ID);

       

      // I build the district value list as a popup menu...where I put the district ID (number) into field 'district_ID_TMP' while displaying the district name to the web user

       

      $district_value_list = "<select name='district_ID_TMP'>";

      foreach($District_Options as $district_name=>$district_ID)

      {

      $district_value_list .= '<option value="' . $district_ID . '">' . $district_name . '</option>';

      }

      $district_value_list .= '<select>';

       

       

      ******

      In spite of passing the record ID, I always get the value list that pertains to the first record.

       

      Suggestions on where I should look next?

        • 1. Re: PHP getValueListTwoFields with a record ID
          rhowe

          Sorry--forgot to mention I'm using Filemaker Server 11 as the host. We're not ready to move to FMP 12 yet...

          • 2. Re: PHP getValueListTwoFields with a record ID
            rhowe

            I worked around the problem by using portals that show the same information (district ID and district name) as the value lists, as using GetField on portal data for the correct record works fine. But I'd still like to know what I'm missing on the value lists....

            • 3. Re: PHP getValueListTwoFields with a record ID
              tduell

              I might recommend that you check out the book FileMaker API for PHP 12, A Practical Guide for Creating Database Driven Web Sites with FIleMaker Pro 12 and FileMaker Server 12. Although it's based on FileMaker Pro 12, the same code applies to 11. The book references all 4 possible scenarios to use the getValueListTwoFields method — custom values, single field, two fields displaying both values and choosing the first field, and two fields showing only the second field, but choosing the first field.

               

              http://www.formulationspro.com/pages/products/products_detail.php?id=101

              • 4. Re: PHP getValueListTwoFields with a record ID
                rhowe

                Thanks for the book suggestion. However, my problem isn't in pulling out the displayValue and/or the value--that I can do. The problem is that in a relational value list (when setting it up in Filemaker, and specifying the fields to use,  you use the "Include only related values starting from...." option) the list will change record by record. When one uses getValueListTwoFields(), the two parameters are the layout and the record ID, where the record ID should provide you with the value list as intended for that record. It seems that the record ID is ignored and the value list from the first record in the layout is provided instead.

                 

                To use a different example:

                With a database of cars, and a value list of accessories based on car model, I might have these matches

                 

                for a Fiat 500: accessories of "spare tire", "floor mat"

                for a Mustang Shelby GT 500: accessories of "competition shifter", "performance clutch"

                 

                If there's a mustang in the record with recordID of 120, the call

                    $accessory_list = $layout->getValueListTwoFields('car_models',120);

                should get me the list with the shifter and clutch when I break out the value list information using

                foreach($accessory_list as $accessory_name=>$accessory_ID)

                { ...

                }

                 

                But what happens is, regardless of the record ID passed in the getValueListTwoFields record ID parameter, I always get the first record's value list; in this case, the spare tire and floor mat.

                 

                ***

                As I wrote earlier, I have worked around this by putting a portal on the layout set up to provide the same information as the value list, and grabbing the portal information instead. But it'd be nice to not have to do double work on the layout end.