Jump to content

Sorting "sorted" records


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

Recommended Posts

Is there a way to sort data while preserving actual sorting order.

e.g. sorting by SALESMAN while already sorted by INVOICE will give me records sorted by SALESMAN then by INVOICE for each salesman.

I know I can specify both sort order in a single "Sort Records[]" script step but i want to sort them using two script steps. I probably have to get rid of the "Restore" in the Sort statement.

I have built a huge sorter script that sort on a specific column base on its name (switch-case), and a string tokenizer that gives me in reverse order all names specified on a comma separated list, but I suspect new Sort script steps to sort as if data were not actually sorted.

Thanks

Link to comment
Share on other sites

I'll take a stab at it. What if you have 2 fields and 3 scripts.

The 2 fields are Salesman# and Invoice#.

The first script changes the numeric value of Salesman#.

The second script changes the numberic value of Invoice#.

The third script sort the records by the numeric values of Saleman# and Invoice#.

This way you can have one sort script and still change the sort order.

Just a thought.

Link to comment
Share on other sites

I'm not sure I understand what you mean.

Are you suggesting to set a "foo" field to salesman# then sort using "foo" then set "foo" field to invoice# then sort again using "foo"? Isn't that what i'm trying to achieve sorting by "invoice#" then "salesman#" expecting invoice# to remain sorted (within salesman block)

If you suggesting to set foo1 to salesman# then foo2 to invoice#... then foo-n to ... then finally sort by foo1, foo2, ..., foo-n it MIGHT work even if it takes more memory. Also we should take care of datatype and either "format" them prior to store them in text field 9 -> "0000009", November 1st -> "20071101" or store them in foonum1, footext1, foodate1, foonum2, footex2, foodate2, ... A lot of extra processing but...

There is a lot of possible fields to sort by and I dont want to rely on FM dialog to set which one I want records to be sorted by. I prefer setting "salesman#, invoice#, itemunitprice, itemname" in a text field or a ScriptParameter then parse it.

Link to comment
Share on other sites

I'm not quite sure what your referring to with "foo" field. What I'm saying is, there is no way to sort records while saving a previous sort order without some way of marking the original sort order.

The fields I was referring to was two number fields. Their sole purpose is to establish and save the sort order. We can call these sort1 and sort2. The way it works is, you sort your records in the first order you want. A script then populates the sort1 field, by putting in a number representing the numerical number. First Record = 1, Tenth record = 10, etc. Then you sort your records in the second order you want. Then do the same for the sort2 field. Once both fields are populated a single script can be used to sort your records based on the two sort fields. What's nice about this is, You only need one sort script. What you decide to sort with stays open.

Link to comment
Share on other sites

okay okay... what I mean by "preserving" the actual sort is to sort by a new column while item having the same value on the new column are still sorted by the previously order.

Till FM is probably using QuickSort algorithm, it's prolly impossible.

Link to comment
Share on other sites

It's me again...

So you suggest something like that

fidx1: Number

fidx2: Number

fidxn: Number

fval1: Text = case(fidx1=1; salesman; fidx1=2; invoice#; ...; "")

fval2: Text = case(fidx2=1; salesman; fidx2=2; invoice#; ...; "")

fvaln: Text = case(fidxn=1; salesman; fidxn=2; invoice#; ...; "")

Sort Records[Restore; No dialog][fval1 ASC, fval2 ASC fvaln ASC]

Link to comment
Share on other sites

Your getting the idea. You'll find you'll have more flexibility by sorting your records based on fields that can change without changing the critical information for that record. For example: fidx1 could = 1,2,50 or anyother number. Whatever that number is, it will only change the sort order, not you records critical information.

Link to comment
Share on other sites

This topic is 6106 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.