FM - Request for Scripting Timesaving Suggestions

Posted on 2011-05-09
Last Modified: 2012-05-11
Had a little project that I thought would take me an hour and ended up taking about 4.  I was to create a new table and pull it back into an existing layout so agents can mark whether someone stood them up on an appointment.  Question:  How do you organize scripts, calcs, etc., to save time?  Use custom functions frequently?  I've also heard something about macro scripts.  I'm new at this.  I'm asking for suggestions, so, of course, there is no right answer.
Question by:rvfowler2
    LVL 24

    Expert Comment

    by:Will Loving
    It's a broad question and the answer - as always - depends on your goals. I'm not sure what is meant by "Macro scripts" but perhaps it's referring to "Master" scripts? I have a set of 50+ "Master" scripts that do various common functions. The advantage to this kind of "modularization" is that if you ever want to change something, you just change it in one place...the master script.

    For example, I have several printing related scripts the do such things as set Page Setup to US Letter/Portrait, show the Status Area, Go to Preview, Pause, Print and then Close the Window. When running a report that needs to be in US Letter Portrait mode, I would use the New Window and Go to Layout script steps to get to the report layout, and then just run the Master script to do the rest. i have similar scripts for US Letter Landscape, US Legal Portrait, A4 Portrait etc as well as options to skip the Preview and just print.

    While I have separate Master Scripts for these various print operations, it would be quite possible to simply have one Master Print script and to pass various Print Parameters to the script using script variables for Page Size, Orientation, Preview, Show Print Dialog, etc. I can go into that more if you wish. In general, using script parameters is a great way to reduce scripting. You have a relatively generic script and then specify what it is supposed to do when you click *this* button via the script parameters.

    The same thing can be done using Custom Menus. If you have a lot of reports, you can create a "Reports" menu. Each menu item calls the same Reports script but the script variable tells it which report to run.

    Custom functions can also be incredibly useful in the same way as modularizing scripts. Instead of doing same calculation for something like formatting currency or percentage as text, you use a Custom Function and just call the function.

    If you want more details on any specific part of this let me know.

    LVL 2

    Author Comment

    Thanks.  I am comfortable with script parameters and use them often (reports, navigation, etc.), as well as custom menus.

    Yes, I was referring to Master scripts and I think I understand your concept, but maybe an example would ensure I understand.  Also, any suggestions of where to use custom functions would be appreciated; I only use it currently for phone number formatting.  

    One other example I was thinking of was the email script.  I always copy that and never reenter all the config info.

    LVL 24

    Accepted Solution

    The attached file contains a set of possible "Master Scripts". This is not a definitive set nor is it even what I would use these days if I were designing something that would only be used in FM 11 and later, but it should give you some ideas. As noted above, the Print scripts in particular could be consolidated into a single script with the action determined using "named" script parameters, something I'll may write a short article on. Most of the scripts do not reference any fields, or layouts at all except via script parameter or calculation.

    A few notes:

    Some of the most useful scripts in here are for window management, including:

    Create New Window OFF-screen
    Create New Window ON-screen
    Move Current Window OFF-screen
    Center Window ON-Screen

    I use these all the time.

    There a group of 'generic' Find scripts that can be used to manage a Find sequence from any layout, provided the layouts are named in a consistent manner. They work from the assumption that the main layout for each area of the database has a simple name such as "Contacts" or "Classes" and that the List View of that the respective List view for that table is called "Contacts List" or "Classes List", and if there is a special Find layout that is called, respectively "Contacts Find" and "Classes Find".

    When determining what to do after a Find, if there is more than one record it always goes to the "List" version of the original layout, if there is only one record, it always goes to the single record view. It does this by noting the original name of the layout and adding or removing the word "List" for calculate where to go.

    The one script that I have not cleaned up but left for you to ponder, is a generic script for an "Email PDF of Current Report". By using this as a sub-script in any report sequence, I can have a PDF created an emailed to a recipient.

    The script could be modified to allow user entry of a email address via a dialog and it also has the option to either use the standard "Send Mail" option or to use SMTP. Since the script was created prior to FM's inclusion of SMTP emailing, and because I have to maintain backwards compatibility, it references the SMTPit Plugin rather than FM's SMTP send but that could be easily changed. You just need to have an Admin field somewhere that the user sets to determine which method of sending email you need.

    LVL 2

    Author Closing Comment

    Thanks Will, that's the type of thing I was looking for.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Pop up windows can be a useful feature of any Filemaker database.  Though best used sparingly, they can be employed in a multitude of different ways, for example;  as a splash screen at login, during scripted processes to control user input, as pick…
    Problem: You have a hosted FileMaker database and users are tired of having to use Open Remote or Open Recent to access the database. They say, "can't you just give us something to double-click on rather than have to go through those dialogs?" An…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now