Here is a “Fun FileMaker Fact” beta…a (macOS only) tool to go to Layout by LayoutID.
Here is the AppleScript...
tellmetoactivate display dialog "Layout ID?" default answer "Enter Layout ID" buttons {"OK", "Cancel"} default button "OK" set layout_id tothe text returned of result
-- set layout_id to layout_id as integer tellapplication "FileMaker Pro Advanced" go tolayoutID layout_id endtell
You will need to check the "Allow Apple events…" Extended Privilege.
My standard library of custom functions includes GetLayoutNumber(layoutID). Internally it looks a lot like the code you posted. It didn't get much use until recently.
I'm playing with a webviewer navigation tool that uses the filemaker/javascript integration. It passes Layout or Script IDs to a script which then uses the CF to decide which layout to display. This is a case which would not work with Layout/Script names ( not unique ). Nor would it work with Layout/Script number ( subject to change ), so the use of ID is necessary.
Even so, I don't want to use AppleScript to resolve the problem.