Jump to content
er777

Simple Sort Script needed

Recommended Posts

er777

Help! HELP! This should be SO simple but I'm tearing my hair out. I am not a FM expert, but I'm not stupid either...

 

All I want to do is create buttons (that trigger scripts) that sort fields in ascending or descending order. By Names or Dates or Numbers.

 

I attempt to duplicate an existing script that works, but for the life of me, I can't see why the modified scripts don't do what they are supposed to.

 

I don't have filemaker advanced, or I could maybe see what the faulty script is doing, but this seems to be such a trivial simple thing I should be able to do.

 

Please, any help would be SO appreciated.

 

er777@ca.rr.com

 

Eddie

Share this post


Link to post
Share on other sites
AHunter3

You have one script each for each possible sort order?

 

Your scripts have one and only one script step, consisting of Sort [restore, no dialog]?

 

You've changed the sort order after duplicating the script each time, changing it to the new sort order?

 

You've checked the button that you're clicking to make sure that the script you THINK that it's calling is the script it's really calling? (e.g., that you didn't duplicate the button the way you did the script and then forget to "point" the duplicated button to the new script)?

 

If all the above is true, turn off "no dialog" so you can see what it's trying to do. Is it restoring the sort order as you would expect (as displayed in the Sort dialog) and then failing to sort it that way, or is it failing to restore the desired sort order?

 

Can you manually sort the db the way you are trying to get your scripts to sort, without error / problem?

Share this post


Link to post
Share on other sites
er777

Thanks so much for your quick response!

You have one script each for each possible sort order?

Yes

Your scripts have one and only one script step, consisting of Sort [restore, no dialog]?

Yes

You've changed the sort order after duplicating the script each time, changing it to the new sort order?

Yes

You've checked the button that you're clicking to make sure that the script you THINK that it's calling is the script it's really calling? (e.g., that you didn't duplicate the button the way you did the script and then forget to "point" the duplicated button to the new script)?[/color]

Yes

If all the above is true, turn off "no dialog" so you can see what it's trying to do. Is it restoring the sort order as you would expect (as displayed in the Sort dialog) and then failing to sort it that way, or is it failing to restore the desired sort order?

 

Not sure where to turn on/off no dialog - would love to see exactly what the errant script is doing. It actually appears to be doing the same thing as the source script even though I have changed numerous things! Very bizarre. If only I could see exactly what the script is saying, but alas i don't have FMP Advanced for the debugging function. But my task is so simple, I shouldn't really need it.

Can you manually sort the db the way you are trying to get your scripts to sort, without error / problem?

Yes - If only I could copy the successful manual sort into a script that I could make a button for... is that possible?

Share this post


Link to post
Share on other sites
AHunter3

Your script step should read:

 

Sort [restore, no dialog]

 

click on that actual line and down below you should see a "no dialog" checkbox. Uncheck it.

Share this post


Link to post
Share on other sites
er777

Thanks

 

Well - your advice has revealed that in fact my script is not doing what I want. Can I record the manual sort and make a script of it?

Share this post


Link to post
Share on other sites
er777

With the script syntax:

 

Set Field [Projests::HiliteSortedBy; "nameA"]

 

I don't understand what "nameA" refers to. I know that the capital A means ascending. At first I thought it was a field named "name", but when I replace it with other fields I have created, I get no logical response.

 

If I knew how to point the script to exactly the field I want to sort, it would enlighten me tremendously...

Share this post


Link to post
Share on other sites
AHunter3

If you manually sort and then create a brand new script that sorts your data, it should default to the last sort order, although you could/should be able to edit it right there, hence you should not have to do it that way.

 

We had to do it that way under FileMaker 6 and before, that was how you DID do it.

Share this post


Link to post
Share on other sites
er777

Now you have hit the crux of this problem.

 

How do I create a sort script that refers to the last manual sort that was done?

 

This HiliteSortedBy command is confusing to me. Do you know what it means?

Share this post


Link to post
Share on other sites
AHunter3

a) Open ScriptMaker

 

b) Locate one of your Sorting scripts

 

c) Double-click it. It should open

 

d) When it does open, the existing set of script steps that constitute your script should be in the right-hand pane of your window.

 

e) Aim your mouse cursor right smack dab at the one and only script step that you've described your scripts as having: Sort [restore, no dialog]. If your script step does not, in fact, say that, please tell us what the heck it does say instead.

 

f) Click that script step. A single-click will do.

 

g) Look to the bottom of your screen and at that point you should see the phrase "no dialog" and a box that either does or does not have a check in it. I am assuming yours does. Uncheck it. If yours already does not have a check in the box please say so.

 

h) Click OK until you get out of the ScriptMaker with your changes saved and give it a try.

Share this post


Link to post
Share on other sites
er777

AHnter3

 

You are very kind.

 

Thanks for your help today.

 

The picture is getting clearer..

Share this post


Link to post
Share on other sites
er777

Here's what the working script actually says:

 

Set Field [Projects::HiliteSortedBy; "nameA"]

Sort Records [Restore:No dialog]

Go to Record/RequestPage [No dialog]

 

As I said earlier, i don't understand what

 

HiliteSortedBy

 

means...

Share this post


Link to post
Share on other sites
AHunter3
With the script syntax:

 

Set Field [Projests::HiliteSortedBy; "nameA"]

 

I don't understand what "nameA" refers to.

 

 

OK, listen up. When someone says do this:

 

Set Field [Projests::HiliteSortedBy; "nameA"]

 

 

It's shorthand for do this:

 

a) Add the script step Set Field to your script

 

b) Once you do, you will notice two buttons at the bottom rigth of the ScriptMaker screen: Specify and Specify Calculation.

 

c) Click "Specify" first. A list of possible fields will pop up in front of you. It either will or will not have Projects as the table name at the TOP of this list. If it does not, click on the table name that is up there and it will pop down a list of possible tables; pick "Projects". Once you're on "Projects" as your selected table, find the field HiliteSortedBy which should be in that list of fields. Once you've clicked on that field name, you can click the "OK" button.

 

d) At this point your script step in the scriptmaker will read: Set Field [Projects::HiliteSortedBy] because that's how FileMaker expresses it — TableName, two colons (::) then field name.

 

e) Now click the "Specify Calculation" button. A big "type whatever you want" box will pop up, with, again, a list of possible fields up above it and a dropdown list of possible tables above that; and off to the right of that, a list of functions that you could choose from. In this case we're going to set the field HiliteSortedBy to a specific text string, not the value of some field or the result of a function, so we're going to ignore the stuff at the top and simply type "nameA" in that box. DO include the quotation marks fore and aft. Click the "OK" button.

 

d) At this point your script step in the scriptmaker will read: Set Field [Projects::HiliteSortedBy, "nameA"] because that's how FileMaker expresses it — TableName, two colons (::) then field name, then comma (,) and then the value to set the field TO. The latter can be a literal text string like "nameA", it can be a field (in which case you're setting one field to the value that's currently in another field), or it can be a calculation equation ranging from 2 + 2 to something fairly complicated assembled with the functions such as Abs(GetAsNumber(Middle(Field X, 3, 7))-Length(Field Y)).

 

Subject, then object. Lightswitch, "off". Cat, "out". Field X, SomeOtherfield_ToSetItTo. Record Creator, Get(AccountName)

 

Set Field [ Projects::HiliteSortedBy; "nameA" ]

 

See?

 

Any questions?

Share this post


Link to post
Share on other sites
er777

Wow

 

Thanks so much for your insight!

 

So, at least in this simple sort, in "nameA", "name" is not so important? I notice that in other of the sort scripts, "name" is replaced by "status", "due" etc -- none of which appear to refer to a field or a table or anything - only a shortened version of the field name.

 

Not one piece of reference that I looked for, including a number of FM books, lays out the definitions of the terms for sorting like you did for me.

 

Again, a million thanks!!

Share this post


Link to post
Share on other sites
AHunter3

Umm, Set Field is not a part of sorting.

 

When you set a field you are making it have a certain value.

 

These sorting scripts may be doing something else before or after they sort, but the Set Field part doesn't intrinsically have anything to do wtih sorting.

 

Based on the field name, I'm guessing the Set Field is being done to provide a visual feedback so you can tell at a glance what the data set happens to be sorted by. "nameA", and so forth, probably constitute a label that appears somewhere on the layout.

Share this post


Link to post
Share on other sites
copies

I had the same question, but since I couldn't find something that was real easy, came up with this method to sort a field. The script toggles back and forth between ascending and descending order. You can assign a script button to a column heading title in List View to sort on various columns, or just create a stand-alone button to sort whatever field you want.

 

First, create a global text field called "Sort Order" which will drive the order in which "Customer Name" is sorted. Then, use the following script which sorts on a field called "Customer Name":

 

If [sort Order = "Ascending"]

Sort Records [Restore; No dialog] (select the "Customer Name" field)

Set Field [sort Order; "Descending"] (click on "Descending Order")

Else

Sort Records [Restore; No dialog] (select the "Customer Name" field)

Set Field [sort Order; "Ascending"] (click on "Ascending Order")

 

Make sure that the "Perform without dialog" box is checked.

 

The script looks at "Sort Order" to determine what the last sort order was, performs the sort using the opposite parameter, then resets the "Sort Order" field to show which sort order was last used.

 

You can create multiple scripts to sort on as many fields as you want.

 

Hope this helps.

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use