# Sort array for report

**URL:** <https://community.glideapps.com/t/sort-array-for-report/72465>\
**Category:** Ask for Help\
**Created:** [April 10, 2024, 6:37pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465 "2024-04-10T18:37:26Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 10, 2024, 6:37pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/1 "2024-04-10T18:37:26Z")

</div>

I have an app for the church I Pastor to manage the Retreat events for the womens group that my wife leads. I need to print a list that I have created using json and joined list and then created an array and print that via docsautomator. The list is not organized. I can’t find a way to group by a field and then sort those groups by the name field.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 10, 2024, 7:19pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/2 "2024-04-10T19:19:28Z")

</div>

Have you tried using a query column to sort the data, and then get your joined list from the query?

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 10, 2024, 7:21pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/3 "2024-04-10T19:21:44Z")

</div>

Duh…no Jeff but I will do that now! Thanks…still on the learning curve and Query slips by me to often!  
Ok I now realize that i can’t do that because I get my data for the joined list from the JSON object that I built and it has 4 different bits of info…and when I sort the data in a query I don’t see that column as an option to add to my JSON build…in other words I sort the name via the Query but I can’t add that query\_name column as part of my JSON…

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 10, 2024, 7:40pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/4 "2024-04-10T19:40:24Z")

</div>

![json list](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/f/4f6aa43b97dbfa9e467b5c71b7e978a0dc4cb220.jpeg)  
I wanted to be able to group by T-Shirt size and then sort those a-z by name…

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 10, 2024, 11:21pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/5 "2024-04-10T23:21:35Z")

</div>

What would you expect it to look like if you want to do “group by”? Then how do you pass that to DocsAutomator? As different arrays?

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 2:50am UTC](https://community.glideapps.com/t/sort-array-for-report/72465/6 "2024-04-11T02:50:47Z")

</div>

I want them grouped by T-Shirt size and then in each group the ladies names would be in a-z order.  
It would be nice to be able to put a few blank lines or a horizontal solid line between the groups. Or I would need to create the arrays for the groups sorted and then create one array from them and pass them to DocsAutomator as one.

From “Thịnh Đinh via Glide Community” \<[notifications@glideapps.discoursemail.com](mailto:notifications@glideapps.discoursemail.com)\>  
To [jerryrankin@gmail.com](mailto:jerryrankin@gmail.com)  
Date 4/10/2024 6:31:39 PM  
Subject [Glide Community] [Ask for Help] Sort array for report

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 11, 2024, 2:54am UTC](https://community.glideapps.com/t/sort-array-for-report/72465/7 "2024-04-11T02:54:38Z")

</div>

@Rupert Am I right that you can not dynamically group things like that when you pass an array to DocsAutomator?

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 3:07am UTC](https://community.glideapps.com/t/sort-array-for-report/72465/8 "2024-04-11T03:07:34Z")

</div>

As far as I know I only get to pass the array and it creates the pdf from that …no manipulation of the data in any way.

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 9:32pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/9 "2024-04-11T21:32:24Z")

</div>

Ok I went to OpenAi and ask it to take the current array and group it by tshirt size and the sort by name a-z and give me the result in another array. Worked and I copied that array into a new column and used it to print via DocsAutomator. That does not fix the issue long term since I did not create the array inside the app and if any of the data changed then it would not be accurate. Still looking to figure it out for future use on events. Thanks.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 11, 2024, 11:09pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/10 "2024-04-11T23:09:59Z")

</div>

Can you show us of an example document you generated with this approach?

You can tell OpenAI to generate the JavaScript function to take the input as you format it, and then output a JSON string that can work with DocsAutomator.

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 11:17pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/11 "2024-04-11T23:17:01Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/f/1f035fdb64bc50cbc16a0cd0c93c39eb67b2d5e6.jpeg)  
Here is a part of the report I generate…

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 11:25pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/12 "2024-04-11T23:25:29Z")

</div>

OpenAI is what is used to create the JS to do the work and then ran that code in Chrome java environment to generate the array output. Then created a new text column and copied array into the text column and pointed DocsAutomator at that column…and bingo.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 11, 2024, 11:32pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/13 "2024-04-11T23:32:27Z")

</div>

So it’s not that you want to group sizes and create different tables, but rather sorting by size first, and then sort by name?

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 11, 2024, 11:59pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/14 "2024-04-11T23:59:19Z")

</div>

Correct…It would be nice to add a couple of blank lines for spacing between them (which I can do by editing the array) but this works. Again would love to be able to accomplish this inside the app in Glide but… someday 😉

J

From “Thịnh Đinh via Glide Community” \<[notifications@glideapps.discoursemail.com](mailto:notifications@glideapps.discoursemail.com)\>  
To [jerryrankin@gmail.com](mailto:jerryrankin@gmail.com)  
Date 4/11/2024 6:42:27 PM  
Subject [Glide Community] [Ask for Help] Sort array for report

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 12, 2024, 4:22pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/15 "2024-04-12T16:22:31Z")

</div>

Can this javascript be executed via a button inside Glide and pass the array from my table to it and receive the resulting array to be passed to docsAutomator to print?

```auto
function groupAndSortByTshirtSizeWithSeparators(items) {
    // Group by t-shirt size
    const groupedBySize = items.reduce((acc, item) => {
        const size = item.line_items_tshirt_size;
        if (!acc[size]) {
            acc[size] = [];
        }
        acc[size].push(item);
        return acc;
    }, {});

    // Create a new array with sorted groups and add separators
    const sortedAndSeparated = [];
    Object.keys(groupedBySize).sort().forEach((size, index, array) => {
        const sortedGroup = groupedBySize[size].sort((a, b) => a.line_items_name.localeCompare(b.line_items_name));
        sortedAndSeparated.push(...sortedGroup);

        // Add a separator if it's not the last group
        if (index !== array.length - 1) {
            sortedAndSeparated.push({"separator": "--------------------------------"});
        }
    });

    return sortedAndSeparated;
}

// Example usage:
const myItems = [
    {"line_items_name":"Trisha Wylie","line_items_room":"PS 307","line_items_roommate":"Mia Paek","line_items_tshirt_size":"L"}, 
    {"line_items_name":"Donna McMurry","line_items_room":"BB 403","line_items_roommate":"Katherine Mitchell","line_items_tshirt_size":"3XL"}, 
    {"line_items_name":"Sue Johnston","line_items_room":"BB 401","line_items_roommate":"Martha Suarez","line_items_tshirt_size":"L"}, 
    // Add more items as needed...
];

const sortedItemsWithSeparators = groupAndSortByTshirtSizeWithSeparators(myItems);
console.log(sortedItemsWithSeparators);

```

---

<div class="post-metadata">

**Author:** ![Rupert](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/rupert/32/44178_2.png) [@Rupert](https://community.glideapps.com/u/Rupert)\
**Post date:** [April 12, 2024, 4:45pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/16 "2024-04-12T16:45:34Z")

</div>

Sorry for late reply @ThinhDinh @pipharvester

Currently grouping is not possible, but it’s much requested and will be available soon. It’ll be set right from the DocsAutomator interface.

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 12, 2024, 7:05pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/17 "2024-04-12T19:05:32Z")

</div>

That is fantastic news!

From “Rupert Hoffschmidt-McDonnell via Glide Community” \<[notifications@glideapps.discoursemail.com](mailto:notifications@glideapps.discoursemail.com)\>  
To [jerryrankin@gmail.com](mailto:jerryrankin@gmail.com)  
Date 4/12/2024 11:55:38 AM  
Subject [Glide Community] [Ask for Help] Sort array for report

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 12, 2024, 11:59pm UTC](https://community.glideapps.com/t/sort-array-for-report/72465/18 "2024-04-12T23:59:48Z")

</div>

Have you tried using a JavaScript column?

You also have to take into account the input is a string, not a JSON object in the column’s view, so parse it accordingly before doing any manipulations.

---

<div class="post-metadata">

**Author:** ![pipharvester](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pipharvester/32/61697_2.png) [@pipharvester](https://community.glideapps.com/u/pipharvester)\
**Post date:** [April 13, 2024, 12:13am UTC](https://community.glideapps.com/t/sort-array-for-report/72465/19 "2024-04-13T00:13:08Z")

</div>

No I have not. I will go read up on JavaScript column.

J

From “Thịnh Đinh via Glide Community” \<[notifications@glideapps.discoursemail.com](mailto:notifications@glideapps.discoursemail.com)\>  
To [jerryrankin@gmail.com](mailto:jerryrankin@gmail.com)  
Date 4/12/2024 7:09:49 PM  
Subject [Glide Community] [Ask for Help] Sort array for report
