Product Logo

CNS Menu

Dynamic Menus

Quick Menu

Introduction

This Quick Menu example shows the most simple way to use CNS Menu with External Function calls. The CNSMenu_DefineQuickMenu function is used to quickly create a menu out of a return delimited list of values. This allows you to build menus out of things like value lists, layout names, table names, and more. It is extremely flexible because you can quickly grab text from a variety of places and hand it off to the plug-in to build and show a menu.
Quick Menu example database

Download Example File

FileMaker Database

Test the Example

To test this example, click the “View Menu” button. You can also add, edit, or delete items in the “Menu Items” field, and then click on the “View Menu” button to see the changes.

When a menu item is clicked, the “You chose…” script will be called which uses a “Show Custom Dialog” script step to show you information about the item you clicked.

How it Works

To understand how creating a Quick Menu works, take a look at the “Show Menu” script in the Manage Scripts/ScriptMaker dialog, which is found in FileMaker’s “Scripts” menu. Once you have Manage Scripts/ScriptMaker open, double click the “Show Menu” script. Next, select the Set Field script step and click the Calculated result: “Specify” button, which opens the “Specify Calculation” dialog. Now you will see the following calculation.

CNSMenu_DefineQuickMenu( “QuickMenuExample” ; Menu::Items ; “You chose…” ) & ¶ &
CNSMenu_ShowMenu ( “QuickMenuExample” )

The first function of the calculation is the CNSMenu_DefineQuickMenu function, which allows us to create the menu. To understand what the parameters are of the function, take a look at the format of the function. Note, more information about any function of the plug-in can be found in the Function Reference

CNSMenu_DefineQuickMenu (Name ; Items ; Script ; DB ; FailScript ; FailDB ; Persistent ; IgnoreMetaTags ; BGColor ; FGColor )

  • The first parameter is the “Name” parameter which is the name you are giving this menu and is used when you need to display or update a menu. For this example, we gave it the name of “QuickMenuExample”.
  • The second parameter is the “Items” which are the actual items you want displayed on the menu and must be in the form of a return delimited list. For this example, the items are coming from the “Items” field, so the field reference of “Menu::Items” is used as the second parameter.
  • The third parameter is the “Script” parameter which is the FileMaker script that will be called when you select a menu item. For this example, the “You chose…” script will be called when an item is clicked.

You may notice there are more parameters available for this function, but they are optional and we are not using them in this example.

Going back to our calculation window:

CNSMenu_DefineQuickMenu( “QuickMenuExample” ; Menu::Items ; “You chose…” ) & ¶ &
CNSMenu_ShowMenu ( “QuickMenuExample” )

Now that you understand the first function of the calculation, take a look at the second function, which is CNSMenu_ShowMenu. This function actually makes the menu appear and just requires the name of the menu (“QuickMenuExample” in this case).

At this point, our menu has been shown using the “Show Menu” script, but what happens when you click an item? Remember where we defined the “You chose…” script in the CNSMenu_DefineQuickMenu? Now we need to take a look at that, so find the script in Manage Scripts/ScriptMaker and edit it. You will be looking at a single script step of “Show Custom Dialog”. Double-click the script step and then click the “Specify” button that is next to the Message field. Now you will have a “Specify Calculation” window that looks like the following.

“Menu choice item: ” & CNSMenu_GetMenuChoice & “¶” &
“Menu choice value: ”& CNSMenu_GetMenuValue & “¶” &
“ScriptParameter: ”& Get ( ScriptParameter )

The Show Custom Dialog script step in this script is just used to show a few of the ways you can get information about what menu item was clicked.

  • The first way is the CNSMenu_GetMenuChoice function. This function returns the name of the menu item that was clicked.
  • The second way is the CNSMenu_GetMenuValue function, which returns the value of the menu item that was clicked. Notice in the “Items” field that the “Three;3” and “Four;4” menu values have a semicolon and then a value after it. The value after the semicolon is the menu item’s value, and is what will be returned from CNSMenu_GetMenuValue. If a menu item does not have a value, the menu item name will be returned from CNSMenu_GetMenuValue.
  • Finally, you can also use FileMaker’s Get ( ScriptParameter ) function to get the menu item value. Just like with the CNSMenu_GetMenuValue function, if the selected menu item does not have a value, the Get ( ScriptParameter ) function will return the menu item name.