I had a similar issue the other day where the globals wouldn't stick. I solved the issue by adding a commit record script step after the global was set.
As for the length of your script, pass the layout name into the script as a parameter. That way your basic script becomes
Go to layout [(get(scriptparameter)]
set field [ gLayoutChoose ; get(scriptparameter)]
without all the else ifs.
Hope that helps.
A couple of questions.
- Does this solution not allow for the status toolbar? A popup menu that changes to a layout sounds like the layout popup menu built into the status toolbar. You might be able to save yourself some pain and scripting if you just control the layouts that the user can switch to by managing layouts and controlling what shows in the list and what does not and grouping the layouts into folders.
- What version of FM are you using? If you're using FM version 10 or newer you can leverage the OnObjectModify script trigger. Create a value list of the layout names you want the user to be able to navigate to, attach that list to your popup menu field, create a script that has the step "Go to Layout [by calculation]" where the calculation is your popup menu field, attach that script to the popup menu field using an OnObjectModify script trigger. If you do this the user will navigate to the layout as soon as they choose the layout name from the popup menu. The only down side to this is the value list of layout names has to match your layout names exactly. If they're off by even a space or a carriage return it will not resolve. This also means that if you ever change a layout name you have to make sure it matches in the value list.
All in all, if you can use the built in layout navigation popup menu I'd say go for that. Why build a tool over again?
I should have taken more time to read the questions.
If your pop up list is on field gLayoutChoose,
The triggered script becomes
Commit record/Request (to get the value to stick)
if [ . . . make sure gLayoutChoose is part of the value list you display . . . )
Go to layout [gLayoutChoose]
. . . add feedback to the user telling they why their change didn't work . . .
Hi Chris and Mike
I am electing to hide the Status toolbar because scripting out Delete etc can not be easily scripted around - am using FM11 Adv.
Normally I would just use buttons but this solution needs quite a few buttons and it gets a bit messy (once you put lots of buttons you tend to start think of splitting them into "logical groups"...)
Plus I need to not show some buttons to all users - so I have a "user/group" thing that defines what things they can see via gLayoutChoose - so it does tick most of the boxes...
I am using "onObject Modify" which does work - attached as a Trigger.
The Commit after each if-else seems to work - so I'll see how it goes now.
Thanks for your comments/help!