Script patterns – Test then act (cont.)


Yesterday we detailed two scripts that would solve the problem presented – test for the FileMaker client being used, and navigate to a specific layout designed for the client.

Today we will try to find other ways to solve the problem. When working through alternate solutions we must bear in mind that there are no wrong answers — just solutions of variable quality and fit.

#3: Run a subscript for layout navigation

This solution aims to put all the layout navigation code into a script that is then called whenever needed. This is done by adding the following to any script that needs to use the client layout navigation:


Perform Script [ “Navigate to Client Layout” ]
# then the rest of the script

The subscript (Navigate to Client Layout) is:


If [ PatternCount ( Get(ApplicationVersion); "Pro")]
   Go to Layout [ "Pro" (system) ]
   Exit Script [ Text Result: "" ]
End If
If [ PatternCount ( Get(ApplicationVersion); "Go")]
   Go to Layout [ "Go" (system) ]
   Exit Script [ Text Result: "" ]
End If
If [ PatternCount ( Get(ApplicationVersion); "Server")]
   Go to Layout [ "Server" (system) ]
   Exit Script [ Text Result: "" ]
End If
If [ Get ( SystemPlatform ) = 4 ]
   Go to Layout [ "WebD" (system) ]
   Exit Script [ Text Result: "" ]
End If
Go to Layout [ "OtherClient" (system) ]

#4: Use a layout routing table

This solution uses a routing table which stores the client and target layout value pairs in JSON.


Set Variable [ $client ; Value: --see below-- ]
Set Variable [ $routing ; Value: --see below-- ]
Go to Layout [ JSONGetElement ($routing; $client) ]

The calculation used for $client is as for #2:


Let ( [ 
  clientVersion = Get ( ApplicationVersion )
]; 
  Case ( 
   PatternCount (clientVersion; "Pro"); "Pro"; 
   PatternCount (clientVersion; "Go"); "Go"; 
   PatternCount (clientVersion; "Server"); "Server"; 
   Get ( SystemPlatform ) = 4; "WebD"; 
   "Other" )
)

The calculation used for $routing is:


JSONSetElement ( "{}" ; 
  [ "Pro" ; "Dashboard Main" ; JSONString ] ; 
  [ "Go" ; "Dashboard Mobile" ; JSONString ] ; 
  [ "Server" ; "Home Server" ; JSONString ] ; 
  [ "WebD" ; "Web Home" ; JSONString ] ; 
  [ "Other" ; "Dashboard Main" ; JSONString ] 
)

This structure means that the layout name does not have to match the client name (as in #2). Although there is still a layout name dependency, the layout name is more flexible.

Which one works for you?

We have come up with four different solutions to our problem – one more than required because we are overachievers!

The next step, which we will go through tomorrow, is to assess each solution and decide on the "best" one for us.


Are you late to the ScriptLogic party? If you have missed out on some of these emails, catch up here: Email Archive​

​

If you know someone else who you think might like this email, you can send them this link to subscribe: Subscribe to ScriptLogic Daily​

​