4 Replies Latest reply on Dec 29, 2014 2:31 PM by JonathonKlassen

    Custom Function { Optional Parameter } HELP



      Custom Function { Optional Parameter } HELP


      Merry Christmas Eve!

      I need help! 

      Im building a Custom Function that will make executing SQL a breeze and Maintenance Free. The only problem is I need to grab field names using the getFieldName(_) function to make this is all come together. But this function will not work when multiple fields are put into a return separated list.

      Example of My Dream;

      SQLComplex( targetField ;{ additional targetFields...}; matchField; {additional matchFields...}; comparisons; {additional comparisons..}; values; {additional values...})

      but since no optional Parameters are allowed into Custom Functions......

      Work Arounds

      - Put the list of fields in quotations; Problem; Tedious, makes the whole Custom Function redundant

      (This is where i get stupid..)

      - Make another Custom Function that takes the fields and returns them into a list of "Field Names",  the voila, put that in any corresponding parameter when needed!  Shouldnt be an issue right?

      Nope, wrong..

      the only way for me to use getFieldName(_) is by each field having its own separate parameter. DERP.. Its the same problem. I could never succumb to building a CF that looks like this;

      SQLFields( field1; field2; field3; field4; field5; field6; field7; field8; field9; field10)

      half the time your only using a couple fields..


        • 1. Re: Custom Function { Optional Parameter } HELP

          Try this method for passing your list of field references:

          List ( GetFieldName ( table::Field1 ) ; GetFieldName ( Table::field2 ) ; .... list as many field references as you need )

          then in your custom function, if this list is passed as a parameter named FieldList, you can use:

          GetField ( GetValue ( FieldList ; 1 ) )

          To access the contents of Table::field1

           Note that by using GetFieldName, this expression will continue to work even if you later enter Manage Database and rename a field or a table occurrence.

          • 2. Re: Custom Function { Optional Parameter } HELP

            Thanks for the reply Phil. If that's the cleanest way available, I still find that messy for a Custom Function. But i appreciate the answer, i wanted to make sure there wasnt any method i was forgetting that could achieve what I wanted. To me the whole point of all this work is for creating the neat/tidy and convenient evaluations that you use heavily. To pass fields like the prebuilt functions would be a dream..

            Is the option of additional parameters so difficult to add for Filemaker in Custom Functions? 

            • 3. Re: Custom Function { Optional Parameter } HELP

              As a fellow user, I'd say it's quite easy using the method that I have described. As a fellow user, changing how this works in custom functions is impossible as this would require Filemaker to make a design change in how the functions work.

              But I don't see that this is really necessary if all you are doing is:

              creating the neat/tidy and convenient evaluations that you use heavily.

              Say your create a "Perimeter" function for irregular triangles, quadrilaterals and pentagons where you want to enter the lengths of  each side and return the sum. You can define a custom function like this:

              Perimeter (s1 ; s2 ; s3 ; s4 ; s5 )

              and to compute the perimeter of a triangle use:

              Perimeter ( 3 ; 2 ; 4 ; "" ; "" )

              • 4. Re: Custom Function { Optional Parameter } HELP

                Your right, it would have to change the way Custom Functions work. The more I realize is the more i realize to not even fathom the idea of Optional Parameters. Especially since it seems this issue has only risen when  trying to grab Field Names. Im using the work around with List & GetFieldName inside the parameters of the Custom Function. 

                My function works great and I appreciate the help. Yet im going to walk away disappointed on this one, I have single scripts that will be using the function over 50 times.

                Current Function performing

                SQLComplex ( List( getFieldName(xJobs::fl_rateWaiting) ; getFieldName(xJobs::fl_rateAxle); getFieldName(xJobs::fl_direction)) ; List( getFieldName(xJobs::division) ; getFieldName( xJobs::status)); List("=" ; "=");  List($division; "Active") )

                The Dream

                SQLComplex ( xJobs::fl_rateWaiting ;[ xJobs::fl_rateAxle; xJobs::fl_direction]; xJobs::division; [xJobs::status]; "="; ["="] ; $division; ["Active"] )