4 Replies Latest reply on Jan 30, 2012 3:51 AM by Marc_Hussey

    Script for adding a field to a layout?

    Marc_Hussey

      Hi all,

       

      Does anyone know of a way of making sure all of the fields you have in a table are present in the layout?

       

      I have a script where I'm adding a field to the table...

       

      Execute SQL [ ODBC Data Source: “Test_Database”; Calculated SQL Text: "ALTER TABLE Test_CreateNewFieldwithScript ADD " & Test_CreateNewFieldwithScript::g_VDF & " VARCHAR" ]

      [ No dialog ]

      Allow User Abort [ Off ]

      Set Field [ Test_CreateNewFieldwithScript::g_TableFieldList; FieldNames(Get(FileName); "Test_CreateNewFieldwithScript") ]

      Commit Records/Requests

      [ No dialog ]

       

      where Test_CreateNewFieldwithScript is the name of the table, and g_VDF relates to global field on my layout that I'm using to nominate the name of the new field.

       

      But now I need to make sure the new field is being added to the layout, I was expecting it to just appear but it doesn't.

       

      Any ideas?

        • 1. Re: Script for adding a field to a layout?
          RayCologon

          Marc_Hussey wrote:

          Does anyone know of a way of making sure all of the fields you have in a table are present in the layout?

           

          Hi Marc,

           

          Assuming you're looking for a method that uses a calculation to compare the fields on the layout with those in the table it points to, you should be able to use an expression along the lines of:

           

          ValueCount(FieldNames(Get(FileName); "YourTOName")) >

          ValueCount(FieldNames(Get(FileName); "YourLayoutName"))

           

          - with the caveat that the table occurrence (TO) name must not also be used for any layouts, otherwise the first instance of the FieldNames( ) function will return the list of fields on the corresponding layout rather than in the underlying table.

           

          Marc_Hussey wrote:

          But now I need to make sure the new field is being added to the layout, I was expecting it to just appear but it doesn't.

           

          For fields created using Manage Database dialog, this is controlled by a setting in preferences (the checkbox option labelled "Add newly defined fields to current layout" in the Preferences>Layout tab). I haven't tried creating fields via an SQL call with the setting enabled, so I can't vouch for whether it works on that mode. But in the interest of simplicity, that's where I'd suggest you start.

           

          Regards,

          Ray

          ------------------------------------------------

          R J Cologon, Ph.D.

          FileMaker Certified Developer

          Author, FileMaker Pro 10 Bible

          NightWing Enterprises, Melbourne, Australia

          http://www.nightwingenterprises.com

          ------------------------------------------------

          1 of 1 people found this helpful
          • 2. Re: Script for adding a field to a layout?
            Marc_Hussey

            Hi Ray, thanks for that... the first part works great

             

            ValueCount(FieldNames(Get(FileName); "YourTOName")) >

            ValueCount(FieldNames(Get(FileName); "YourLayoutName"))

             

            As for the second part, if I create a field manually in the Manage Database screen, the field does appear on my layout.  However doing it through the SQL call with the setting enabled, it doesn't appear.  If you can think of any way round this I would really appreciate it!

             

            Cheers

             

            Marc

             


            • 3. Re: Script for adding a field to a layout?
              RayCologon

              Marc_Hussey wrote:

              ...As for the second part, if I create a field manually in the Manage Database screen the field does appear on my layout.  However doing it through the SQL call with the setting enabled, it doesn't appear.  If you can think of any way round this I would really appreciate it!

               

              Hi Marc,

               

              Sorry to hear that the Field Options setting doesn't help in your case. I'm not entirely surprised, but it was worth trying.

               

              I don't believe there are any native tools in FileMaker that will add a field box to a layout for you automatically (ie via script), so you may need to look at third-party tools or scripting environments. A tool such as FMrobot might be able to be called into service in some way, as might some of the other more recent workspace tools.

               

              The only native alternative I'm aware of is a little convoluted. It involves providing a display mechanism to show the contents of the field - ie a viewer mechanism that returns field values automatically based on a list of field names (eg from the FieldNames( ) function) and a stacked parallel system that retrieves fields for editing and posts the edited values using script triggers and Set Field By Name (again, referencing the list returned by the FieldNames( ) function to determine which field was edited). Doubtless not as straightforward as you were hoping, and possibly unsuitable for other reasons also.

               

              Regards,

              Ray

              ------------------------------------------------

              R J Cologon, Ph.D.

              FileMaker Certified Developer

              Author, FileMaker Pro 10 Bible

              NightWing Enterprises, Melbourne, Australia

              http://www.nightwingenterprises.com

              ------------------------------------------------

              • 4. Re: Script for adding a field to a layout?
                Marc_Hussey

                Hi Ray,


                Thanks for the help.  I've marked yours as the correct answer as I believe there's no way of getting filemaker to do what I'm after.

                 

                I'm going to suggest it to Filemaker for future releases.

                 

                Thanks again

                 

                Marc