Sorting excluding articles (The, La, Los, Der…)

Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch Forums Using Tap Forms 5 Sorting excluding articles (The, La, Los, Der…)

Viewing 3 reply threads
  • Author
    Posts
  • July 7, 2024 at 9:16 AM #50895

    David Gilbert
    Participant

    There is at least one previous post about this topic, to get records not to sort by articles, where writing a script is suggested.
    I have a music title database with titles in many languages, so getting the sorting right is important. I’m thinking of setting up two fields, a display title and a sorting title. The records would sort by the sorting title:
    Étoile
    Jahsager
    Man in the High Castle

    But the form would only include the display title, and so the sort would appear like this.
    L’Étoile
    Der Jahsager
    The Man in the High Castle

    Not like this:
    Der Jahsager
    L’Étoile
    The Man in the High Castle

    It’s a lot of work to do this obviously, so I’m checking to make sure there is no other easy solution. Also, I guess this will work?
    Muchas gracias,
    David

    • This topic was modified 2 years, 2 months ago by David Gilbert.
    July 7, 2024 at 4:13 PM #50901

    Brendan
    Keymaster

    Hi David,

    You could do this with a Script Field. Something like this:

    function Sortable_Title() {
    var title = record.getFieldValue('fld-3b1b39ccf20f43e583fe66b8aaa0602c');
    var sortableTitle;
    
    if (title.startsWith('A ')) {
    sortableTitle = title.substring(2);
    
    } else if (title.startsWith('An ')) {
    sortableTitle = title.substring(3);
    
    } else if (title.startsWith('The ')) {
    sortableTitle = title.substring(4);
    
    } else {
    sortableTitle = title;
    }
    
    // console.log(sortableTitle);
    
    return sortableTitle;
    
    }
    
    Sortable_Title();
    You could enhance it to support other article words if you like.
    Thanks,
    Brendan
    • This reply was modified 2 years, 2 months ago by Brendan.
    August 20, 2026 at 12:33 PM #54468

    Ray Kloss
    Participant

    I am having this same problem but have not used Scripts in TFP before. I am creating a database of my movies and want the sorting to not include articles (such as A, The, An). I took the script above and modified the field ID for mine, but since I have never used scripts before, I don’t know what to do with the script. It only pertains to my field “Title“ but I didn’t want to do a text manipulation to actually remove the article. Is this created as a script form? Am I still sorting by the title or by some other field? I put this in my database and ran it, but it didn’t seem to do anything. I am still sorting the database by “title“ but should I use some other field? I could create a field that removes the article, Hyde that field and then sort by that field, but I was wondering if there was a more elegant way of doing this?

    August 20, 2026 at 3:26 PM #54469

    Brendan
    Keymaster

    Hi Ray.

    You add a new field to your form with the Field Type set to Script.

    Then use the above script in the field. Set the Field ID to be your Title field.

    Then you set the First Sort Field to this Script field, not the Title field.

    After you add the Script Field, you may need to refresh the records list to update the result in all the records.

    Thanks,

    Brendan

Viewing 3 reply threads

You must be logged in to reply to this topic.