5 Replies Latest reply on Apr 28, 2017 11:29 AM by Dobieg5750

    Passing Through Variables to PSoS

    Dobieg5750

      Hey all - just thought I'd ask how you pass along variable data from the client to the server when running a Script On Server.

       

      Currently, I create a dummy table in which I pass along Global Variables ($$) to the fields (deleting all records, adding new record, set field) in a record, jumping to my PSoS script, going to that table and pulling the values from the 1st record (only having created a single record) and assigning them to Globals ($$) on the server side for ease of calculation scripts here.

       

      This was the only thing holding me back from running lengthly and timely scripts on the server....couldn't figure out a good way of sharing data that wasn't getting over to the server. This is my work-around and of course I'm now flying through what was burdensome lag on running scripts (push button/go refill coffee).

       

      Anyway, how do YOU do this? Any more efficient ways of getting simple values from the client to the server side of things for quick scripts and calcs?

       

      SG

        • 1. Re: Passing Through Variables to PSoS
          philmodjunk

          You can pass parameters to a script performed by Perform Script On Server just as you do with a script performed by Perform Script.

           

          Some people set up custom functions to manage this, others concatenate multiple values in a single string and then, at the beginning of the script, parse different parts of the parameter into different variables.

           

          A very commonly used method is to set up a parameter expression in the PSOS call that looks something like this:

           

          List ( Value1 ; Value2 ; Value3 )

           

          Then, in the beginning of the script:

           

          Set Variable [$FirstParameter ; value: GetValue ( Get ( ScriptParameter ) ; 1 ) ]

          Set Variable [$SecondParameter ; value: GetValue ( Get ( ScriptParameter ) ; 2 ) ]

          Set Variable [$ThirdParameter ; value: GetValue ( Get ( ScriptParameter ) ; 3 ) ]

           

          Nearly all the time, that's all you need, but you do have to be aware of two very important limitations:

           

          Value1 and Value2 cannot be empty or Value3 won't make it into the right $Variable.

           

          None of the values can be a block of text with a return in it.

           

          For that reason, there are also other options used to pass parameters to a function. They all combine multiple values into a single parameter string and the parse them into separate values inside the script, but differ in detail.

          1 of 1 people found this helpful
          • 2. Re: Passing Through Variables to PSoS
            Dobieg5750

            Ok so I might have over-thought it (and am honestly finally getting around to digging in to options for PSoS and learning more about it).

             

            I currently run a script, perform some client-side stuff, then call (within that script) a Perform Script on Server and do the heavy lifting there.

             

            Could I set a variable in my initial script of let's say $IDWhatever and have that variable be available in my PSoS script (since I'm calling that script within my script where $IDWhatever was set?

             

            Did I over think things?

            • 3. Re: Passing Through Variables to PSoS
              Jason Wood

              Your method of deleting fields and recreating is risky if there is any chance of more than one PSOS running at the same time (e.g.: by multiple users)

               

              You should be passing this information through the Script Parameter. Phil perfectly illustrates the potential downfalls of using a carriage-return separated list, so if these potential problems apply to you, I would suggest looking at the "#" custom functions in the starter file at filemakerstandards.org

               

              Your script parameter might look like:

               

              #("myVar"; $$myVar ) & #("myInfo"; Table::MyField ) & ...

               

              Then when you need to use them in the server script, you can pull them out with #Get(Get(ScriptParameter);"myVar") and #Get(Get(ScriptParameter);"myInfo"), OR you can use #Assign(Get(ScriptParameter)) to load all the values into local variables named based on the keys ($myVar, $myInfo).

               

               

              • 4. Re: Passing Through Variables to PSoS
                philmodjunk

                Could I set a variable in my initial script of let's say $IDWhatever and have that variable be available in my PSoS script (since I'm calling that script within my script where $IDWhatever was set?

                 

                You have to pass that value as a parameter in the PSOS script call. Any global field or variable (global or otherwise) data in your current client will not be accessible from the server side session created by the PSOS call.

                 

                You have one readily available means to send data to the PSOS script, the script parameter and one way to pass data back to the cient session from the PSOS script: Exit Script [ Put value or expression here]. And then use Get ( ScriptResult )  to access data returned from the PSOS script.

                • 5. Re: Passing Through Variables to PSoS
                  Dobieg5750

                  I gotcha.

                   

                  So while I created a "3 lefts to make 1 right" work-around (originally), as both of you pointed out: there is a right way and a way to avoid potential same-time conflict errors.

                   

                  I looked at script parameters briefly before but did not invest the proper time in becoming fluent in it.

                   

                  Seems like I have my marching orders...appreciate the feedback!