# Easy way to know if script is being run on the server

**URL:** <https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382>\
**Category:** Questions\
**Tags:** filemaker-server\
**Created:** [October 9, 2020, 2:41pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382 "2020-10-09T14:41:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JasonMark](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@JasonMark](https://the.fmsoup.org/u/JasonMark)\
**Post date:** [October 9, 2020, 2:41pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/1 "2020-10-09T14:41:35Z")

</div>

I have a script that I _sometimes_ run locally and sometimes on the server. I can pass in a variable to know if it's on the server or not, but is there an easy way to test if script is being performed on a server or locally?

---

<div class="post-metadata">

**Author:** ![EfficientBizz](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/efficientbizz/32/252_2.png) [@EfficientBizz](https://the.fmsoup.org/u/EfficientBizz)\
**Post date:** [October 9, 2020, 7:16pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/2 "2020-10-09T19:16:10Z")

</div>

I use not a script to detect, but a process that performs script on server if there is FMServer hosting the files, otherwise perform local:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# name: \_template\_PSoS

# purpose:

# description: Host is Server AND we're Client =\> PSoS Script "self", Exit, else =\> THE SCRIPT

# dependencies:

# used in Layout/Script: Universal

# comments: set ahead of every Script

# Author: EfficientBizz GmbH - Benjamin Fehr

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# 

# 

If [// Host is Server PatternCount ( Get(HostApplicationVersion) ; "Server" ) and // we're NOT on Server PatternCount ( Get(ApplicationVersion) ; "Server" ) = 0]  
Set Variable [$$progressbar ; Value: 1]  
Refresh Window []  
If [Abs (Get(ApplicationVersion)) \<17]  
Perform Script on Server [Specified: From list ; “\_template\_PSoS” ; Parameter: PSoS\_coordinates\_Set ( "Value" ) /\* $Layout $FieldName $ID $Parameter $Value _/ ; Wait for completion: On]  
Else  
Perform Script on Server [Specified: By name ; Get ( ScriptName ) ; Parameter: PSoS\_coordinates\_Set ( "Value" ) /_ $Layout $FieldName $ID $Parameter $Value \*/ ; Wait for completion: On]  
End If  
Set Variable [$$progressbar ; Value: 0]  
Set Variable [$$PSoS\_Error ; Value: Get(ScriptResult)]  
Exit Script [Text Result:]  
End If

# 

If [// - Server-Side - PatternCount ( Get(ApplicationVersion) ; "Server" )]  
Set Variable [$PSoS ; Value: PSoS\_coordinates\_extract /\* $Layout $FieldName $ID $Parameter $Value \*/]  
# Find  
Go to Layout [$Layout ; Animation: None]  
Enter Find Mode [Pause: Off]  
Set Field By Name [$FieldName ; $ID]  
Perform Find []  
End If

# 

# THE SCRIPT - either Server OR Client

# 

# 

#

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [October 9, 2020, 9:18pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/3 "2020-10-09T21:18:28Z")

</div>

Question: Why fork the code for application version less than 17?

I can see that you are able to use "specify by name" for 17 and up, and that you can then call get(script name). That section of code is very portable - you can cut/paste and change the script name without having to modify the perform script call, but that isn't available for earlier versions.

My question is really why you choose to implement the new code? The code that works for versions less than 17 will work perfectly well for newer versions.

---

<div class="post-metadata">

**Author:** ![EfficientBizz](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/efficientbizz/32/252_2.png) [@EfficientBizz](https://the.fmsoup.org/u/EfficientBizz)\
**Post date:** [October 10, 2020, 12:00pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/4 "2020-10-10T12:00:06Z")

</div>

That‘s correct. It‘s a template to copy/paste at the beginning of every script to build a hybrid to work either local OR as PSoS if an FMS Host is detected.  
For the „Fork“: I needed downward compatibility for a user running FMS16.  
There ara 2 CustomFunctions involved to first write „coordinates“ for current focus (Table, Layout, PrimaryKey) for second cf to resolve on server side (PSoS).

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [October 10, 2020, 5:01pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/5 "2020-10-10T17:01:36Z")

</div>

> I have a script that I _sometimes_ run locally and sometimes on the server. I can pass in a variable to know if it's on the server or not, but is there an easy way to test if script is being performed on a server or locally?

Hello @JasonMark

Many devs will use the output of the [Get( ApplicationVersion )](https://help.claris.com/en/pro-help/index.html#page/FMP_Help%2Fget-applicationversion.html) function as a means to determine whether or not the code is currently running on the server.

Hope this helps solve what you are after.

-steve

---

<div class="post-metadata">

**Author:** ![JasonMark](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@JasonMark](https://the.fmsoup.org/u/JasonMark)\
**Post date:** [October 10, 2020, 6:03pm UTC](https://the.fmsoup.org/t/easy-way-to-know-if-script-is-being-run-on-the-server/1382/6 "2020-10-10T18:03:03Z")

</div>

> [@EfficientBizz](#):
>
> PatternCount ( Get(ApplicationVersion) ; "Server" ) = 0

Thanks, I saw this in the original script and figured it's the way to do it. Thanks all!
