Jump to content

dynamic sorting


This topic is 7930 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm trying to make an "Ultimate" Filemaker find and sort subroutine, where I just pass some lists to the subroutine, and it returns the found fields, sorted in the order I requested. I don't want to bore you w/the entire script, so I'll just ask about the sort part, which is where I'm getting stuck.

I know FMP likes to sort in this syntax:

sort by {field "State", field "Date"} in order {ascending, descending}

So I'm trying to write a script to build that sort from 2 lists. Here's how far I've gotten, but i'm stuck on how to build a list that looks like {field "abc", field "xyz"} .

Can someone help?

TIA.

Dan

set theFieldsToSortList to {"State", "Date"}

set theSortOrderList to {"ascending", "descending"}

tell application "FileMaker Pro"

tell database "xyz"

set SortFieldList to {}

set SortOrderList to {}

repeat with i from 1 to the length of theFieldsToSortList

set thisSortField to item i of theFieldsToSortList

set thisSortOrder to item i of theSortOrderList

set SortFieldList to SortFieldList & field & thisSortItem

set SortOrderList to SortOrderList & thisSortOrder

end repeat

sort bySortFieldList in order SortOrderList

end tell

end tell

Link to comment
Share on other sites

Use this syntax:


set fieldlist to {"LastName", "FirstName", "PhoneNo"}

set orderlist to {"ascending", "ascending", "descending"}

set sortfieldlist to {}

set sortorderlist to {}

tell application "FileMaker Pro"

repeat with i from 1 to (count fieldlist)

set itemsortorder to ascending

if (item i of orderlist) = "descending" then set itemsortorder to descending

set sortfieldlist to sortfieldlist & {a reference to field (item i of fieldlist)}

set sortorderlist to sortorderlist & itemsortorder

end repeat

sort by sortfieldlist in order sortorderlist

end tell


Link to comment
Share on other sites

  • 1 month later...

Thanks Bob! That SO did it! I've been using this subroutine for a while now and it's been great... Until...

I just loaded OS X 10.2 on my computer, and now Filemaker crashes when I invoke this sort subroutine, with the error: The Connection is invalid. I even made a dummy database to test it, and it crashed the dummy too. I'm using FMP 5.5v2. Any ideas?

Link to comment
Share on other sites

Never mind. I figured it out myself. I had

Tell app "Filemaker"

tell database theDatabase

-- find code goes here

end tell

-- sort code goes here

end tell

for some reason this worked great until 10.2. Now it requires

Tell app "Filemaker"

tell database theDatabase

-- find code goes here

-- sort code goes here

end tell

end tell

Link to comment
Share on other sites

This topic is 7930 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.