1 2 3 Previous Next 60 Replies Latest reply on Apr 18, 2017 2:18 PM by what?

    Perform script on server

    what?

      I have a script that contains at a least 15 loops that access and process through as many as 100 records.  My solution is hosted on a service on server 14.  My solution has been created in 13. 

       

      When I run this script on web direct it runs in 2 seconds (I presume because it is running on the server).

       

      When I run this script on direct client (open remote) or iOS it takes several minutes or chugs forever (again because i presume it is running on the client and a lot of data is choking back and forth)

       

      I don't think that I can optimize the script because it requires going to each record, setting a variable to the value of a score in that record, then moving to the next record, comparing the variable to the value of the score in that record.  Then, if the values are equal, assigning an equal ordinal to a field in both records, then bumping an ordinal variable up + 1 or + 2, etc. to accommodate the tied situation.  This loops until the last record has been dealt with.  I am finding ties and assigning places with ordinals.  When I built the script on my mac, I didn't notice a problem, because the script ran lightning fast.  As it is now, the script is unusable when hosted.  I thought about just using the replace field contents command, then assigning serial numbers for ordinals, then constraining my found records with !, this would find my ties.  Then I could use the comparison technique mentioned above on far fewer records.  Filemaker won't let me constrain a clean find of my first find set and the duplicates within that set.  I have already done some successful work with self relationships putting a summary of all records in a portal on each record, but I don't know how to use this alien context concept for constraining my found set, as has been suggested online. 

       

      I want to give psos a try, but, I can't figure out how to do this or if it would even be practical with my 200 + lines of code.  I have tried calling filemaker help, but they "are not developers".  The online filemaker psos instructions are too limited in scope or detail for me to understand in the context of my database solution.  I am doing something wrong or leaving something out.  I can upload one of my loops if that would help.

       

      Thank you anyone!  I am self taught and apparently I am not the best of teachers in this area.  I also have difficulty assimilating filemaker jargon, although I keep working at it.

        • 1. Re: Perform script on server
          databuzz

          I can't see any issues with not using PSOS here - you just need to remember that PSOS doesn't know anything about your current session (e.g. found set, layout etc), so you need to be explicit in your PSOS script so that it will know which layout to be on, whether to do a find to create a found set to start the loop with, what to do when it encounters an error etc.

           

          Just write the PSOS script assuming it knows nothing and you have to tell it everything that it needs to know in correct order - I would suggest making a backup copy of the file and using that when testing as well. Make sure you're only using "server" compatible script steps as well.

          • 2. Re: Perform script on server
            dougnewnham

            What Databuzz says is the big gotcha.  You will need to pass records/find criteria from your client session to the server script so it knows what found set to process, what layout to go to.  Also, if you have any start up scripts with steps that are not compatible with server side scripting you'll need to bypass by a check on within the startup script.

             

            I am a novice but have invested a lot of my learning into PSOS.  The biggest issue is you are often testing it 'blind' so to speak so set yourself up a log file so you can write out progress of your script while you are de-bugging.

            • 3. Re: Perform script on server
              Jason Wood

              Also look into other reasons why this script is slow.

               

              Does the script navigate to layouts that have unstored calculations or summary fields, or even script triggers on them? If so, there may be a whole lot of extra work being done throughout the script that's completely unrelated and unnecessary.

               

              If you don't already, consider setting up BLANK records layouts for every table, and use these for your scripts.

               

              Edit: Blank layouts, not records. Thanks databuzz!

              • 4. Re: Perform script on server
                databuzz

                I think Jason meant BLANK layouts here - good advice.

                • 5. Re: Perform script on server
                  wimdecorte

                  Jason Wood wrote:

                   

                  Also look into other reasons why this script is slow.

                   

                   

                   

                  I'll second that.  If you have 100 records and you need to do what you describe you shouldn't need that many loops through the records.  If you do need to loop a lot through the data then collect the data in a variable using one of the many techniques to do so and do the looping on the variable(s) and then do an actual loop through the records to update the data.

                  • 6. Re: Perform script on server
                    what?

                    Thank you Jason, Databuzz, winmdecorte, and dougnewnham for your responses.

                     

                    I will first try the latest response involving packing all of the 15 actions into one loop.  I am depending on your expertise here to let me know if 15 actions in one loop is faster than 15 loops each with one action.

                     

                    I still would like to try psos, but I don't know how to start with it.  I'm sorry to say that your responses assume that I know how to do it.  I need an example showing me exactly how it's done for something simple, like go to layout x or a few lines of the code that I have attached.  I have come to understand that I learn differently than most people.  Inputting new information into my knowledge base is very difficult.  I need very detailed, clear, step by step explanations of new material such as psos.  Once I get the concept I am usually ok and can process. 

                     

                    With psos do I make a separate script that says perform script on server that references another script such as the one I have attached? I assume that I put in wait for response and a parameter in the perform script on server that tells the server what layout I am on.  Then in the referenced script I start with go to layout by calculation get script parameter?  I have tried this 100 times with no result.  I am trying to run a race with a blindfold on and no idea where to start.  I am sorry if explaining this is way below your pay grade, but I don't know what else to do.

                     

                     

                    Attached are the first several lines of  my script.

                     

                    Thank you in advance, and I understand if this is too far below you to explain.

                     

                     

                    Exp Apply Ordinals Skipping Numbers: New Apply Ordinals Resolve Ties Find Caption Winners

                     

                     

                     

                    Go to Layout [ “Master Recap” (Judging Prototype) ]

                    #Music Perf Ind Apply ordinals skipping numbers when there are ties

                    If [ Get ( AccountName ) = "Music Perf Ind Judge" or Get ( AccountName ) = "Master Recap" or Get ( AccountName ) = "Tabulator" or Get ( AccountName ) = "Cyberscoreadmin" or Get
                    ( AccountName ) = "Ken All Access" ]

                    Sort Records [ Keep records in sorted order; Specified Sort Order: Judging Prototype::Master Recap Music Individual; descending ]
                    [
                    Restore; No dialog ]

                    Go to Record/Request/Page

                    [ First ]

                    Set Variable [ $MusicIndOrdinal; Value:1 ]

                    Set Field [ Judging Prototype::Music Ind Ordinal; $MusicIndOrdinal ]

                    Set Variable [ $MusicIndCompareScore; Value:Judging Prototype::Master Recap Music Individual ]

                    Go to Record/Request/Page

                    [ Next ] Loop

                    If [ $MusicIndCompareScore=Judging Prototype::Master Recap Music Individual ]

                    Set Field [ Judging Prototype::Music Ind Ordinal; $MusicIndOrdinal ]

                    Set Variable [ $MusicIndCompareScore; Value:Judging Prototype::Master Recap Music Individual ]

                    Go to Record/Request/Page

                    [ Next ]
                    If [ $MusicIndCompareScore=Judging Prototype::Master Recap Music Individual ]

                    Set Field [ Judging Prototype::Music Ind Ordinal; $MusicIndOrdinal ]

                    Set Variable [ $MusicIndOrdinal; Value:$MusicIndOrdinal + 2 ] Else

                    Set Variable [ $MusicIndOrdinal; Value:$MusicIndOrdinal + 1 ] Go to Record/Request/Page

                    [ Previous ] End If

                    Else

                    End If
                    Go to Record/Request/Page

                    [ Next; Exit after last ] End Loop

                    End If

                    #Music Perf Ens Apply ordinals skipping numbers when there are ties

                    If [ Get ( AccountName ) = "Music Perf Ens Judge" or Get ( AccountName ) = "Master Recap" or Get ( AccountName ) = "Tabulator" or Get ( AccountName ) = "Cyberscoreadmin" or Get
                    ( AccountName ) = "Ken All Access" ]

                    Sort Records [ Keep records in sorted order; Specified Sort Order: Judging Prototype::Master Recap Music Ensemble; descending ]
                    [
                    Restore; No dialog ]

                    Go to Record/Request/Page

                    [ First ]

                    Set Variable [ $MusicEnsOrdinal; Value:1 ]

                    Set Field [ Judging Prototype::Music Ens Ordinal; $MusicEnsOrdinal ]

                    Set Variable [ $MusicEnsCompareScore; Value:Judging Prototype::Master Recap Music Ensemble ]

                    Go to Record/Request/Page

                    [ Next ]
                    10 ScoreStat MB.fmp12 - New Apply Ordinals Resolve Ties Find Caption Winners -1-

                     

                         

                     

                    Set Variable [ $MusicIndOrdinal; Value:$MusicIndOrdinal + 1 ]

                    Set Field [ Judging Prototype::Music Ind Ordinal; $MusicIndOrdinal ]

                    Set Variable [ $MusicIndCompareScore; Value:Judging Prototype::Master Recap Music Individual ]

                     

                        

                     

                    April 6, 2017 9:10:55

                     

                    • 7. Re: Perform script on server
                      dougnewnham

                      Here's an extremely basic example.  And please keep in mind that this was probably my first handful of scripts I ever wrote in FM! 

                       

                      Let's say I have a table that contains records unique per user.  When the user first logs in I want to delete all records from their last session and reload another set from somewhere. Deleting records over a WAN can be painfully slow so I decide to PSOS.  If you imagine your server is 'blind'.  When PSOS executes the server has no context.  The script when run on the client might look like this:

                       

                      Set Error Capture [on]

                      Set Variable [$Userid; value: fmUsers::ID]

                      Go to Layout [RoundPlanner (fmRoundCliPlanner)]

                      Enter Find Mode [Pause:off]

                      Set Field [fmRoundCliPlanner::userid;$userid]

                      Perform Find []

                      If [get(foundcount) <>0

                      Delete All Records [With dialog:off]

                      End if

                      Set Error Capture [off]

                       

                      If I simply call this Script as

                       

                      Perform Script on Server [Wait for completion; "Delete Round Cli Planner | UserID"]

                       

                      then the server has no context for fmUsers::ID and if your startup script doesn't handle being run on the server could produce undesirable outcomes.  I need to tell the server which user I want to process this script for so; it changes to:

                       

                      Set Variable [$Userid; value: Get(ScriptParameter)]

                      Go to Layout [RoundPlanner (fmRoundCliPlanner)]

                      Enter Find Mode [Pause:off]

                      Set Field [fmRoundCliPlanner::userid;$userid]

                      Perform Find []

                      If [get(foundcount) <>0

                      Delete All Records [With dialog:off]

                      End if

                      Exit Script [Text Result: "some text to confirm it was successful"]

                       

                      and I call it by passing the userId as a script parameter.  So I need two scripts.  One that runs when the user starts the app that contains the following:

                       

                      Go to Layout [fmUsers (fmUsers)]

                      Perform Script on Server [Wait for completion; "Delete Round Cli Planner | UserID"; Parameter: fmUsers:ID]

                      Show Custom Dialog [Get(ScriptResult)]

                       

                      and the second one that is called by PSOS.

                       

                      You can of course turn off "Wait for completion" because I am using the script result.  I've also removed error capture as I believe this has no effect when used on Server.  Also, make sure dialog is turned off (Incompatible script step). When starting out; always have your script workspace set to display incompatible steps when running on server.

                       

                      I'm now doing these types of things a lot more efficiently after some great sessions at DevCon and very helpful people in these forums but I thought it best to keep it simple at this stage.

                      • 8. Re: Perform script on server
                        what?

                        Thank you.

                         

                        I will study this and try to make an example from my understanding that will fit my my solution. BTW what does <> 0 mean?

                        • 9. Re: Perform script on server
                          dougnewnham

                          Sorry, That was meant to be >0.

                           

                          <>0 was my fingers working with SQL coding in mind.  It means "does not equal"

                          • 10. Re: Perform script on server
                            what?

                            I have studied your sample psos script.  I thought that I understood it, however, when I tried a simple example on my solution, I couldn't get it to work.  It would help me a lot if you could send me the exact scripts related to the following example:

                             

                            on mac

                             

                            My solution is hosted on a service fmphost.com on server 14

                             

                            My solution was designed on filemaker pro advanced 13 (updated from 11)

                             

                            I created a new blank layout called Experiment

                             

                            I created a new field called Experiment

                             

                            I wish to create a psos script that will insert the number 25 (as a test) in my experiment field on my experiment layout.

                             

                            I have tried every permutation of psos and its target script that I can think of, and still nothing.

                             

                            Thank you so much in advance!

                            • 11. Re: Perform script on server
                              BruceRobertson

                              SHOW us exactly what you tried.

                              Where is the copy of your script?

                              Or better yet, a copy of your file.

                              EDIT: attached - my simple example.

                              • 12. Re: Perform script on server
                                BruceRobertson

                                Please tell us more detail. So far:

                                You do not say anything about the TABLE that holds this new field.

                                You do not say anything about how you know it did not work.

                                You do not say anything about which table the layout is based on.

                                • 13. Re: Perform script on server
                                  dougnewnham

                                  Yes...we're trying to help so you need to give us as much information as possible.  "I've tried everything" doesn't help us help you!

                                  • 14. Re: Perform script on server
                                    wimdecorte

                                    what? wrote:

                                     

                                     

                                    I have tried every permutation of psos and its target script that I can think of, and still nothing.

                                     

                                     

                                     

                                    There are no permutations of PSoS.

                                     

                                    PSoS is a script step.  The script that you 'attach' to the step will run.  You need to make the script does what you want it to do.  That is no different with PSoS than with a regular script.  Your solution is in what the script does, not in some magic setting of the PSoS script step.

                                     

                                    Keep in mind that the script runs virtually as a new user, newly opening the solution.

                                     

                                    That means these usual gotchas:

                                    - whatever OnOpen scripts you have in the file will run before the target script. So check that whole chain of script for incompatible script step

                                    - the target script does not know the layout or found set that you are on.  If your intent is for the PSoS to set a field in the record that you happen to be on then you have to construct the target script so that it goes to the proper record first.

                                     

                                    All of this would be whole lot easier to explain if you showed us exactly what you are doing.

                                    1 of 1 people found this helpful
                                    1 2 3 Previous Next