Sorting on multiple criteria based on user input
I'm working on a Filemaker Database (using Filemaker Pro 9) that searches and displays data from a large data set. I've written an interface for searching, but I'm a bit stuck as to how to script the sorting of the data.
I want users to be able to sort on up to three categories (e.g. last name, city, zip code, etc) with up to eight choices of sort order for each of the three - so, for example, they could sort by (last name; state; zip code) or (zip code; city; last name), or (first name; country; last name) etc. I really want to script this, rather than letting the users use the built-in sort function - mostly so I can limit which fields they can search by, but also so I don't have to train all the users how to properly use search!
Unfortunately, the Sort Records script step doesn't seem to take any input other than fixed fields - I can script "sort by Last Name" but not "Sort by [calculation to get field name]". I could do this with a series of if statements for every possibility, but with three options and eight permutations there'd be 512 options to code - it seems like there must be an easier way!