8 Replies Latest reply on Oct 9, 2014 12:46 PM by philmodjunk

    Changing layout based on field value

    WiserGuy

      Title

      Changing layout based on field value

      Post

      Hi,

      I've been struggling with a script to change layout if a certain value exists on a field. The idea is that this specific value triggers another table occurrence - hence the need to change layout.

      My problem is that all my efforts seems to loop the script (based on OnLoadRecord). A script example or alternative solutions to solve this will be most appreciated.

      Thanks,

      WG
       

        • 1. Re: Changing layout based on field value
          RickWhitelaw

          OnRecordCommit perhaps?

          • 2. Re: Changing layout based on field value
            philmodjunk

            Sounds like your trigger controlled script is tripping it's own scrip trigger and thus getting trapped in an infinite loop. Is that the case? There are simple methods to avoid that trap.

            • 3. Re: Changing layout based on field value
              WiserGuy

              Rick: I believe I need OnRecordLoad. I can't see how I can use OnRecordCommit.
               

              Phil: Yes, it's trapped in a loop, and there is probably a very easy way around it. But I can't seem to get my head around it. Anyway, it's a new day here in Europe now, and maybe a good night's sleep helps me figure it out!?.

               

              • 4. Re: Changing layout based on field value
                philmodjunk

                I would like to see the actual script that you are using.

                To post a script to the forum:

                       
                1. You can upload a screen shot of your script by using the Upload an Image controls located just below Post a New Answer.
                2.      
                3. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
                4.      
                5. If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                6.      
                7. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
                • 5. Re: Changing layout based on field value
                  WiserGuy

                  Phil,

                  I have fooled around with a lot of script, using one for each layout trigger, and one combined. A combined one would be neatest.

                  I read a previous post from you regarding enclosing triggers into if statements using global variables. After trying an failing, I ended up with a script which worked without indefinite loops 90% of the time when using find mode. The problem was also that browsing through records didn't seem to work, hence the "show all records" step. I have used variations around the following script:

                  Set Variable [ $$Serial; Value:tbAssets::SerialNo ]
                  If [ tbAssets::Type = "Rig" and not $$TriggersOff ]
                  Set Variable [ $$TriggersOff ; Value:True ]
                  Go to Layout [ “Asset Details Rigs” (tbAssets_RigView) ]
                  Show All Records
                  Perform Find [ Specified Find Requests: Find Records ; Criteria: tbAssets_RigView::SerialNo : “$$Serial” ]
                  [Restore]
                  Show All Records
                  Set Variable [ $$TriggersOff ; Value:False ]
                  End If  “Asset Details Rigs”

                  So the idea is to change layout from "Asset Details" to "Asset Details Rigs" or vice versa depending on the data in tbAssets:Type ("Asset Details Rigs" if value is "Rig", "Asset Details" if all other values.


                   

                  • 6. Re: Changing layout based on field value
                    philmodjunk

                    The script shown cannot trip it's own script trigger as it is correctly using the $$TriggersOff global variable

                    and this:

                    Show All Records
                    Perform Find [ Specified Find Requests: Find Records ; Criteria: tbAssets_RigView::SerialNo : “$$Serial” ]
                    [Restore]
                    Show All Records

                    Makes no sense

                    The performed Find will produce identical results whether or not the preceding step is Show All Records.

                    The second Show All records then completely cancels out the results of the perform find by showing all records all over agin.

                    I suspect that some other trigger is being tripped and that script is interfering on you.

                    • 7. Re: Changing layout based on field value
                      WiserGuy

                      You are correct this does not loop with this script, but when I have a similiar script on the other layout, it does loop. Not when coming through find or a list, only when browsing through the records with "previous" and "next". For some reason the browsing seems to trigger something with the recordset using the scripts. On my test table there are only 8 records, same records shows fine on both portals when browsing through them in the portal. But using the scripts, when on record 5 which triggers a layout change, the layout change switches to record 2.

                      But I've left the problem for now, as browsing is not likely to be needed on this layout anyway. But I will probably try again later - don't like leaving a buggy script behind.

                      Thanks, Phil!
                       

                      • 8. Re: Changing layout based on field value
                        philmodjunk

                        but when I have a similiar script on the other layout, it does loop

                        Then why did you not post that script? The details can be critical so a "similar" script may fail in a way that the one shown does not. A simple misspelling could be enough to cause an issue here.

                        What script trigger are you using on the layout? OnRecordLoad?

                        And then you mention a portal and that leaves me scratching my head in confusion as you did not mention such earlier and I do not see what the current row of a portal might have to do with a script tripping it's own script trigger when you browse records on the layout.