8 Replies Latest reply on Jul 19, 2013 5:58 PM by demattfx

    Running a script from within a calculation

    demattfx

      Is there a way to trigger and run script with a calculation field?

        • 1. Re: Running a script from within a calculation
          schamblee

          If you have Filemaker Advance you can create a custom function that would be accessible in a calculation

          • 2. Re: Running a script from within a calculation
            Mike_Mitchell

            Exactly what are you trying to accomplish? Most likely, what you want to do can be accomplished via one or more Script Triggers.

             

            Mike

            • 3. Re: Running a script from within a calculation
              demattfx

              I'm trying to run a script for a field that is type "calculation" because a script is the only way I can get to the value I  want to assign to that field. Finding the value I need requires both "perform find" and perform "sort" script steps. I know I can do it using a script trigger for the table that the field is in but it  would require looping thru the the entire set of records each time to maintain the correct value for the field in all the records, which slows everything down.

              If I could do  it as a field "calculation" FMP would automatically maintain the correct value for  the field anytime something changes that affects it for all records in that table.

              • 4. Re: Running a script from within a calculation
                jbante

                Can you tell us any more details about the substance of the result you want, and how it will be used? The best approach may not be in the direction you're thinking, but we can't tell you that without more background information.

                 

                You can't trigger a script via a calculation (without a plug-in). If calculating the correct value requires a find and a sort, and you're using FileMaker 12, you may be able to get the same result without a script using the ExecuteSQL function. If you have to loop through "the entire set of records each time" you need to update the value, you may have an architectural problem.

                • 5. Re: Running a script from within a calculation
                  demattfx

                  The field  I want to calculate the value for is derived from another table which is linked to this table. The value is derived is the earliest date that occurs for a group of found records in the linked table. The table that the calculated field is in a group of records (242).  Each record in this table could be looked at as a report for a given group of events out of the linked table. Does that make sense?

                  • 6. Re: Running a script from within a calculation
                    Mike_Mitchell

                    Can you not do that with a summary field (minimum value)? Can you set up a break field that defines each group and put a subsummary part on your layout?

                     

                    Mike

                    • 7. Re: Running a script from within a calculation
                      sporobolus

                      on 2013-07-19 18:22 demattfx wrote

                      The field  I want to calculate the value for is derived from another table which is linked to this table. The value is derived is the earliest date that occurs for a group of found records in the linked table. The table that the calculated field is in a group of records (242).  Each record in this table could be looked at as a report for a given group of events out of the linked table. Does that make sense?

                       

                      what sort of find operation do you need to do? if you could define a

                      relationship that gives you the same related set as the find would, then you

                      can sort the relation and simply reference the field in the related table

                      without needing a calc field at all; if you need to capture the date as of a

                      given point in time a lookup could do it; if you need to keep updating the

                      value, relookup the value or use ExecuteSQL in a calc

                      • 8. Re: Running a script from within a calculation
                        demattfx

                        Thanks Mike

                         

                        What you suggested works great, with  one additional twist. I have a portal in the layout in which the field in question is located. The portal shows the group of records from the linked table that are of interest  to me. So when I created the summary field as you suggested it summarizes only the records that are in the portal.Perfect solution!!

                         

                        Thanks Much

                         

                        Frank