Hello! I recently started using the Perform Script on Server command. I haven't needed it before or didn't think I did.
I'm curious about a best practice
I develop webdirect apps and I always have a "OnFirstWindowOpen" script. This script usually handles setting up variables based on the current user. The app uses domain groups to log in so the user is authenticated as they come in. However, on most of my apps, I maintain a list of users that can be managed by an admin of that particular app. So, in this OnFirstWindowOpen script, I might set a variable such as "$$IsAdmin, or $$ValidUser", etc - based on this user table.
What I just found out is that if I do a Perform Script on Server, the server actually logs in and hits this script. It took me a little debugging to figure that out since I didn't expect it. I thought it would just run the command I provided.
I therefore added the following statements to the top of the OFWO script -
If LeftWords ( Get (ApplicationVersion) ; 1 ) = "Server" and Get(SystemPlatform)<>4
Exit Script
End If
I also had to tell my app in the security to all fmapp logins. I didn't have that checked before. In the OFWO script, I already tell the user they have to be in WebDirect, so I didn't have an issue, however the server wouldn't log in.
This all works great, however it really makes me wonder if I shouldn't be using an OnFirstWindowOpen script in the first place. Have I been using a wrong approach all along OR is it normal to add a server login check to scripts in apps that might use Perform Script on Server?
What is a best practice for this?
I can't remember a single system where we didn't have a OnFirstWindowOpen (we call them startup) script running, so you're in good company.
As you say, any PSOS or server run script will activate this script. We tend to use a couple of options, one being to pass a parameter within the PSOS call and the startup script is set to exit script upon checking for this script parameter if true.
The other is a variation on your suggestion If ( PatternCount ( Get ( ApplicationVersion ) ; "server" ) > 0 ) ) then exit script. I started a thread some time ago about the best method for this and there were about 3 variations all of which worked fine.
Also, do not forget that any 'OnLastWindowClose' scripts will be triggered as well.
We carried out a lot of investigation and testing to fully understand what goes on with PSOS. This was some time ago, but I've lifted the logs from one of these tests that records the whole process (IP address anonymised):
- Startup Script Info:
Account Name: Andy Hibbs
Application Version: Server 15.0.3
Device:2
Extended Privileges: fmapp
fmreauthenticate10
fmwebdirect
Host Name: FMS5
Persistent ID: C185BC20E5152671A80B94972761DD93
System Drive: /C:/
System IP Address: xxx.xxx.xxx.xxx
System NIC Address: 00:50:56:b9:88:10
System Platform: -2
System Version: 6.3
Temporary Path: /C:/Windows/Temp/S67057/
User Name: PSOSScript - Andy Hibbs 358
Use System Formats State: 0
- PSOS Script Info:
Account Name: Andy Hibbs
Application Version: Server 15.0.3
Device:2
Extended Privileges: fmapp
fmreauthenticate10
fmwebdirect
Host Name: FMS5
Persistent ID: C185BC20E5152671A80B94972761DD93
System Drive: /C:/
System IP Address: xxx.xxx.xxx.xxx
System NIC Address: 00:50:56:b9:88:10
System Platform: -2
System Version: 6.3
Temporary Path: /C:/Windows/Temp/S67057/
User Name: PSOSScript - Andy Hibbs 358
Use System Formats State: 0
- Shutdown Script Info:
Account Name: Andy Hibbs
Application Version: Server 15.0.3
Device:2
Extended Privileges: fmapp
fmreauthenticate10
fmwebdirect
Host Name: FMS5
Persistent ID: C185BC20E5152671A80B94972761DD93
System Drive: /C:/
System IP Address: xxx.xxx.xxx.xxx
System NIC Address: 00:50:56:b9:88:10
System Platform: -2
System Version: 6.3
Temporary Path: /C:/Windows/Temp/S67057/
User Name: PSOSScript - Andy Hibbs 358
Use System Formats State: 0
- FM Pro Info:
Calling Script:
Account Name: Andy Hibbs
Application Version: ProAdvanced 16.0.1
Device:2
Extended Privileges: fmapp
fmreauthenticate10
fmwebdirect
Host Name: FMS5
Persistent ID: E6E56E723D46D52059068134E2D01F06
System Drive: /C:/
System IP Address: xxx.xxx.xxx.xxx
System NIC Address: 00:50:56:b9:30:6a
System Platform: -2
System Version: 6.3
Temporary Path: /C:/Users/andyhibbs/AppData/Local/Temp/3/S10.1/
User Name: Andy Hibbs
Use System Formats State: 1
0
If anyone is interested, at a time when I'm less busy, I can list the actual tests in order to make sense of the above. Also, during these tests we found the bug in PSOS in v15 where the FMP client could not update quickly enough to display the correct results without a pause for 0 seconds after the PSOS has run, which FileMaker fixed on a subsequent release.
Now, if we could have a script step option 'Suppress Script Triggers', life would be much easier
Kind regards
Andy