[rt-users] Custom fields sort order

Brent brent at skyblue.eu.org
Sun Oct 23 17:31:09 EDT 2005

I doubt this is the correct way of doing it but it worked for me as my users
where pestering me about it.
What I did was to create a perl script (my perl is very rusty and very
immature so if anyone can make this better be my guest)
I couldn't figure out how to put the output of a select query into a perl
array so I just created a bash script that called the perl script (nasty!)
echo "select Name from CustomFieldValues where CustomField = 5 order by Name
into outfile '/tmp/mysqlselect' LINES TERMINATED BY '\n';"|mysql -Drt3
rm -f /tmp/mysqlselect
Obviously here you need to find out the value of your CustomField beforehand
and the perl is (I went to perl as I had issues with trying to get the bash
array going properly)
use DBI();
  # Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=rt3;host=localhost",
                       "root", "blah",
                       {'RaiseError' => 1});
my $data_file;
open(DAT, $data_file) || die("Could not open file!");
my $count=0;
foreach $names (@names) {
        print "UPDATE CustomFieldValues SET SortOrder = $count WHERE Name =
'$names'\;\n ";
        $dbh->do("UPDATE CustomFieldValues SET SortOrder = $count WHERE Name
= '$names'");
I just added this to a cron script to run every night at 12 or something so
any updates will only be visible to the user after that unless you manually
run it each time.
And this has sorted the customfields alphabetically and got my users off my
back for now.
There must be a better way than this but I didn't have the time to look into
it too much (likewise for my select going directly to the array!)


From: rt-users-bounces at lists.bestpractical.com
[mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Brent
Sent: 20 October 2005 18:27
To: rt-users at lists.bestpractical.com
Subject: [rt-users] Custom fields sort order

Is there a way to change the order of custom fields so they can be sorted
For eg when adding items to a custom field I would like it to automatically
sort the items alphabetically instead of numerically.
So items inserted in this order
get sorted to 
etc etc?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20051023/49d0930b/attachment.htm>

More information about the rt-users mailing list