|INM V12 Database for Director||Windows, Macintosh||Searching and sorting||3.x Regular & Light|
It is sometimes useful to retrieve each value only once in a database. This is possible to achieve in INM V12 Database by using the mGetUnique method. This method returns unique values of the Master Field in a string or a Lingo list.
mGetUnique is very convenient to populate a user interface element (such as scrolling list or pull-down menu) with search values that are relevant only for a specific database and context. For instance, clicking on a menu would develop all possible values for a given field. Then, by choosing one, the field that contains the records is updated, showing only the values that matches the selection, and each of the other menus are updated to show the new valid choices!
Example: In a clothing catalogue, you want to display only the available colors for a specific category and size of product (e.g., T-shirt and XXL). You run the following script:
mSetCriteria(gTable, "category", "=", "T-shirt") mSetCriteria(gTable, "and", "size", "=", "XXL") mOrderBy(gTable, "color") mSelect(gTable) put mGetUnique(gTable, "literal") into field "ScrollList"
This script retrieves unique values of the "color" field (which is the Master Field) to the field "ScrollList". Assuming that your selection contains 30 records (10 with Color = "Red", 10 with Color = "Green" and 10 with Color = "Blue"), the above script puts the string...
... in field "ScrollList".
This example can be easily understood with a complete code sample. We suggest you download the sample available here. It demonstrates a user-interface where searches in a V12 Database file are performed through dynamic pop-up menus. The contents of the menus are constantly updated to reflect the actual values available in the V12 Database selection.
In this sample, at start-up, each menu is built by retrieving the selection (mGetSelection) for a specific field, sorting it, removing duplicates and finally placing the result in the pop-up menu.
When the user selects an item in a pop-up menu, a search is performed in the V12 Database file with the appropriate keyword and all menus are updated again, as described above.
This sample is supported on Director 6.5 and later.