8 Replies Latest reply on Feb 10, 2016 4:18 PM by KevinWojniak

    PHP: Portal field is empty


      I have a layout that has many portals on it. I am trying to obtain its data via PHP and up to now it's been successful. However, one specific portal is being stubborn, and I cannot get all of its fields. I am using the exact same code (getRelatedSet, getField) but the fields are returning empty strings, except for one field. I can see in the layout in FileMaker that these fields are in the portal and that they have "Display data from" set in the Inspector. Oddly when I use getFields() it's not returning all the fields that I see in the portal. Most of the fields are calculations. Also, for the actual item I want, "Display data from" is "Multiple Values" and I cannot find what that means or how that is configured differently. I've been comparing the Inspector window and am not seeing a difference.


      So I am looking for hints as to why I cannot get this one portal's fields in PHP.

      Note I am not the one who designed this database, just a programmer trying to get some data out of it.

        • 1. Re: PHP: Portal field is empty

          Make sure the fields in the portal are from the same relationship as a portal. In inspector for a field "Display data from"  part before :: has to be the same as the name at the bottom left of the portal (in layout mode).

          I am not sure about "Multiple Values" in, can you explain where do you see it?

          • 2. Re: PHP: Portal field is empty

            Thanks for the reply.


            All but one field belongs to the same table, but I don't need that field. Here is a video showing the fields in the portal and the Multiple Values issue:



            If that Flash doesn't show it clearly (or work) you can download the direct movie here:

            Dropbox - FileMakerPortal.mov


            As I mentioned above when I get a record for this portal and call getFields(), I only get this back (using print_r on the portal record object):


                [0] => Quotations::LineItemAdditionalInfo
                [1] => Quotations::LineItemName
                [2] => Quotations::ItemQuantity
                [3] => Quotations::LineItemAdditionalInfo2


            The only field in that array that I see is in the portal layout is LineItemName, I'm very confused as to why it's showing these other fields that aren't in the layout, and not showing the actual fields that are in the layout.

            • 3. Re: PHP: Portal field is empty

              Thanks for the video.


              When you select LineItemName it appears as Quotations::LineItemName. Quotations is the name of the relationship the portal is based on. It is the same name you can see on the portal bottom left corner.

              The reason you see Multiple Values is because you have multiple fields stacked on top of each other and grouped. If you ungroup them you will see the fields from you array. I am still suspicious why you are not getting couple of calc fields values.


              I would suggest removing all fields from the portal and off the layout and adding them one by one making sure the relationship is correct. Also try to make portal row bigger and make sure field boundaries are within the portal row.

              In any case, which field value you are getting and which one you are trying to get?



              • 4. Re: PHP: Portal field is empty

                Ah, that grouping makes sense now that I see it.


                I found the problem! There are multiple Quotations portals on this layout, and the one that getRelatedSet() is pulling is the first one in the layout (hidden behind layers of tab controls), not the actual portal I want. Now it all makes perfect sense.


                Now for a new problem: how to get the PHP API to pull this specific portal I want? Using this code it only shows a single entry for "Quotations":


                $lay = $fm->getLayout('MyLayout');


                I may have to go directly to the XML API...

                • 5. Re: PHP: Portal field is empty

                  I was going to suggest checking this as the next step.


                  I don't think you can chose which portal to retrieve if they are based on the same table occurrence.


                  What stops you from adding the field you need to get to the portal you are getting now? They are from the same relationship on the same layout, so you will get the same result.


                  Another workaround is to create another table occurrence, a duplicate of Quotations and call it differently, e.g. Quotations_php. Make sure the relationship predicates are the same, create a portal based on the new TO and retrieve data from there. Does this make any sense?



                  • 6. Re: PHP: Portal field is empty

                    I would like to avoid modifying the layout in any way.


                    After poking in the XML file I verified that multiple related sets with the same name are actually returned, so it's just the PHP API that is lacking.


                    I found an alternative API https://github.com/soliantconsulting/SimpleFM which also didn't support this feature, but I was able to patch it (https://github.com/soliantconsulting/SimpleFM/pull/56). It's still a little hackish in that you need to look at the keys for the portal record to identity which portal it is, and that may not always be perfect. SimpleFM also has a "portalindex" value it sets internally which you could use too. Either way, the data is at least accessible.


                    Now, after that massive detour, back to what I was actually trying to accomplish . Thanks for your help nicolai!

                    • 7. Re: PHP: Portal field is empty

                      Glad you managed to find a solution. Just one more thing before you go - it sounds like you get data from the end-user facing layouts in FileMaker. The common practice is to generate separate set of layouts for php use only.



                      • 8. Re: PHP: Portal field is empty

                        I can see the advantage of that due to performance, but what about duplicate logic with scripts, or formatting?