6 Replies Latest reply on Jun 5, 2012 12:23 AM by JohnMitchell

    Syntax of Script Arguments

    JohnMitchell

      I have a multi-file solution; three of these files (Activities.fmp12, Organisations.fmp12 & Persons.fmp12) call a script in Persons.fmp12 with a common list of arguments.

       

      This syntax (option A) works from Organisations, Persons and its other table Staff:

      ...

      #update current employer

      Set Field [ Organisations::gCurrent_employeeID; selected employee Person::PersonID ]
      Set Field [ Organisations::gCurrent_staffID; selected employee::StaffID ]
      #call Skype or telephone
      Set Field [ Organisations::gScriptArgs; "PersID = Organisations::gCurrent_employeeID ; StaffID = Organisations::gCurrent_staffID; Context = "Employee" " ]

      Perform Script [ “perCall_person_Skype” from file: “Persons”; Parameter: Organisations::gScriptArgs ]

      ...

       

      but from Activities the above syntax doesn't work, but the syntax below doesfrom Activities

      ...

      Set Field [ Activities::gCurrent_persID; selected member Person::PersonID ]

      Set Field [ Activities::gCurrent_staffID; selected member Staff::StaffID ]

      Set Field [ Activities::gScriptArgs; "PersID = " & Activities::gCurrent_persID & " ; StaffID = " & Activities::gCurrent_staffID & " ; Context = "Member" " ]

      Commit Records/Requests
      Perform Script
      [ “perCall_person_Skype” from file: “Persons”; Parameter: Activities::gScriptArgs ]

      ...

       

      Here is the common script in persons:

      Persons: perCall_person_Skype

      #1 June 2012

      #select a telephone contact for a person and Skype

      #scriptArgs: PersID, StaffID, Context: either as Employee - 3 modes "Member", "Employee", "Staff" or individual "Person"

      Allow User Abort [ Off ]

      Set Error Capture [ On ]

      Set Field [ Persons::gCurrent_personID; getParam ( "PersID" ) ]

      Perform Script [ “Set_choice_null” ]

      Go to Related Record [ From table: “current Person”; Using layout: “Contact employee” (Persons) ] [ Show only related records ]

      Set Field [ Persons::gForm_header; "Contact " & getParam ( "Context" ) ]

      If [ getParam ( "Context" ) "Person" ]

      #CASE A: select the employment details
      #set the selected Staff member
      Set Field [ Persons::Selected_staffID; getParam ( "StaffID" ) ]

      Go to Layout [ “Contact employee” (Persons) ]

      Else

      Go to Layout [ “Contact person” (Persons) ]

      End If

      ...

       

      Q1: Is Option A syntax correct? (it never gives an error while editing the script)

      Q2: If the Organisations example is correct, why doesn't the Activities script work?

        • 1. Re: Syntax of Script Arguments
          erolst

          Compare the two script steps where you set field gScriptArgs. This calculation

           

          Set Field [ Organisations::gScriptArgs; "PersID = Organisations::gCurrent_employeeID ; StaffID = Organisations::gCurrent_staffID; Context = \"Employee\" " ]

           

          should probably read:

           

          Set Field [ Organisations::gScriptArgs; "PersID =" & Organisations::gCurrent_employeeID & " ; StaffID =" & Organisations::gCurrent_staffID & " ; Context = \"Employee\" " ]

           

          The placement of the quotes in the first, non-working version makes the calculation syntactically correct, but simply yields a text string without evaluating the field values and setting your key/value-pairs.

          • 2. Re: Syntax of Script Arguments
            JohnMitchell

            tks for your feedback;

             

            what is puzzling is that the first calc you quote works in 3 cases while this format does not work in one case and needs the second syntax (whcih I agree looks more like the correct way to do it).

             

            The Help does not help ! because it only gives a very simple one argument example...

            • 3. Re: Syntax of Script Arguments
              jbante

              There's more than one workable way to structure multiple script parameters, but the most popular are return-delimited values and various name-value pair schemes. Judging by your example, I'm guessing you prefer name-value pairs. Without knowing how your getParam() custom function works, I can't say if you're syntax is correct or not. With name-value pairs, I find that it's helpful to use custom functions not only to extract values from the parameter, but also to build the name-value pairs — it keeps the syntax simple. There's a discussion of name-value pair functions here on FileMakerStandards.org, and you can find implementations on GitHub here.

              1 of 1 people found this helpful
              • 4. Re: Syntax of Script Arguments
                sporobolus

                on 2012-06-04 1:51 JohnMitchell wrote

                what is puzzling is that the first calc you quote works in 3 cases while this format does not work in one case and needs the second syntax (whcih I agree looks more like the correct way to do it).

                 

                it looks like Evaluate() is used by your getParam() to obtain the values for

                these parameters; assuming so, your note on what does/doesn't work shows the

                difference between what could be called early and late binding of the parameter

                values; i think if you reason through how these work, you'll probably discover

                why late binding in your particular cases worked only sometimes

                 

                late binding is also called "pass by name": if the field name referenced is

                within quotes as in the first example, the name of the field is passed to the

                called script and it won't be evaluated until the getParam() function runs; if

                the called script is in a different file, the field name may be out of scope so

                Evaluate() won't be able to get the field value

                 

                early binding, or "pass by value": if the field name referenced is outside the

                quotes as in the second example, the value of the field, rather than the name

                of the field, is inserted into the parameter string; Evaluate() will be able to

                assign this value regardless of context

                 

                 

                to add to jbante's comment, my own parameter passing technique converts all the

                named parameters in a parameter string into local variables, and allows

                optional parameters and default values, without a lot of hand-wringing:

                 

                <http://www.briandunning.com/cf/453

                • 5. Re: Syntax of Script Arguments
                  JohnMitchell

                  steve - an excellent explanation, but I need some clarification.

                   

                  I've checked the Persons file which contains 2 tables Staff & Persons; in the dialog to select a field I have Related and Unrelated Tables, and in the latter category when opening from a Staff field, I get "Persons" and "Organisations" as actual entries in the relationships list.

                   

                  And now as might be expected in the Activities file there are no Unrelated Table entries.

                   

                  What is the difference between Related and Unrelated, as in the graph for Persons there are many relationships to Activities, and vice versa?

                   

                  What is the subtlety here?

                  • 6. Re: Syntax of Script Arguments
                    JohnMitchell

                    Thanks Julian - I will investigate your reference - tks an excellent resource.