9 Replies Latest reply on Oct 12, 2015 10:28 PM by ayescas

    Perform Script Step on Server and Global Variables

    ayescas

      Hello TechNet,

       

      I have a script using Perform Script, which basically creates a record and sets a field with a Global Variable. 


      Works fine, but here is my issue:

       

      Instead of using "Perform Script" I want to use "Perform Script on Server"  because the script creates hundreds of records and I want to improve the performance.  Now the records get created, but the global ($$) variable are not being set.

       

      I read the following: "Global variables can be used if they are defined AFTER the script begins running on the server", so I tried using a "Replace All" script-step after the script ran on server and my global variable are still not setting.  What am I missing?

       

      -Alex

        • 1. Re: Perform Script Step on Server and Global Variables
          Extensitech
          AFTER the script begins


          versus


          after the script ran

           


          See the difference?


          A global field has the same value regardless of what record you're on even what table (occurrence) you're referencing it from, so "replace all" (which I assume was "replace field contents"?) is not necessary. Just set the field and it's set for all records.


          On the other hand, a global is also unique to the user session. The server setting a global field won't affect what's in the global field on any other computer, or what's in that field the next time the server runs a script.


          Thus, a global used PSOS can't be set before the script runs, because before the script runs the server doesn't have a session, and even if it did your changes to the global in your session wouldn't show for the server in its session. The server can only retrieve values in global fields that it put there itself. Also, if the script sets a global, you won't be able to see that back on your machine, in your session.


          Does this help?


          Chris Cain

          Extensitech

          • 2. Re: Perform Script Step on Server and Global Variables
            user19752

            "Perform Script on Server" runs on server with creating virtual client on server, it start from opening the file, then no variables (and current layout, found set, sort order, etc) are shared with caller. You need to pass the values via script parameter and do some other things.

            • 3. Re: Perform Script Step on Server and Global Variables
              ayescas

              So , if I pass the global variable from the client to the sever  via a script parameter it a Should work???

              • 4. Re: Perform Script Step on Server and Global Variables
                ayescas

                Thanks Chris,

                 

                What's the best way to pass a variable from client to to PSOS ? 

                • 5. Re: Perform Script Step on Server and Global Variables
                  Extensitech

                  As you've said, via script parameter works great. You can also get results back as a script result.

                   

                  There seem to have been a lot of threads about globals lately, and it's got me thinking about how to best explain them without just making a long list of their oddities. It occurs to me, though, that it's helpful to think of them more like $$variables than fields, and go from there. If you think of them that way, there's actually not as many differences as between global fields and other fields.

                   

                  The main differences between a global field and a $$variable (that I can think of off the top of my head) is that you can use global fields on the "left" side of a relationship, and that global fields can't be changed in the data viewer by a non-full-access user with FMPA. There are probably a few more, but I think even a comprehensive list would be shorter than even a cursory list of differences between global fields and other field types.

                   

                  Particularly, for the matter at hand, global variables are very much like $$variables: You can set them from anywhere and they apply everywhere, but only for this user's session.

                   

                  Anyhow, if you pass a script parameter to the PSOS script, use it there, and then pass your result in a script result, your client's original script can pick up the result and run with it.

                   

                  HTH

                   

                  Chris Cain

                  Extensitech

                  • 6. Re: Perform Script Step on Server and Global Variables
                    ayescas

                    Thank you Sir....going to dive into that right now !!!   

                     

                    Last comments....sorry I come from a brut-froce way of doing things, but is it correct to interpret the following:


                    "Global variables can be used if they are defined AFTER the script begins running on the server."

                     

                    "Global variables can be used in PSOS only if passed via script parameter. "

                    • 7. Re: Perform Script Step on Server and Global Variables
                      Extensitech

                      "Global variables can be used in PSOS only if passed via script parameter. "

                       

                      Almost. That PSOS script can set globals itself, and then read those results. The main thing is, setting a global on your local machine won't set it on the server, and vice-versa, so anything you need to set on one machine and read on the other needs to be passed via script parameters/results, or set into a regular field to be read by the other machine.

                       

                      Chris Cain

                      Extensitech

                      • 8. Re: Perform Script Step on Server and Global Variables
                        ayescas

                        The nail finally went through the wood...lol.  thank you for taking the time.  I'm putting it together right now....

                        • 9. Re: Perform Script Step on Server and Global Variables
                          ayescas

                          Just ran a test and it works....thank you so much.