SELECT then ORDERBY (date)

First, sorry if this has been posted before. I did find a few others similar to my question, but since no one listed any information for their tables or what their data was for, it was confusing.

I have a table that has all of the vehicles the company owns called Vehicles and then there’s a table called Comment, which holds all of the comments for vehicles. We use those comments to add information related to each vehicle.

Using a virtual column on the Vehicles table with:
SELECT(Comment[uuid], [smartsheet_row]=[_THISROW].[ref_id])

Displays all my comments perfectly. The issue I have is the comments show up randomly and not by the date they were added. At the top of comments there could be a new one, the one after can be a year old, and then one from last week. It is very strange.

ORDERBY(SELECT(Comment[uuid], [smartsheet_row]=[_thisrow].[ref_id]), [date_sent])

That did not help. I read on another post where someone recommended using MINROW and another TOP, but since the person who opened that topic never explained their tables or columns, it didn’t help much.

We imported data from smartsheet, so the smartsheet = ref_id which is the vehicle numbers.

Any help with this would be appreciated.

On the database:

A snapshot of the table column definitions in AppSheet would be more helpful.

Check that the UUID column is actually set as the key column in AppSheet. Also, check that the [date_sent] column in AppSheet is set as DateTime.

Barring any issues with the above, you might try wrapping the [date_sent] column with the DATETIME() function just to see if that makes any difference…DATETIME([date_sent])

1 Like

The rows of an inline table (such as the one in your screenshot) are ordered according to the inline view’s configuration, not by the order of the list elements themselves. ORDERBY() will have no effect in this case.

In the UX >> Views tab of the app editor, look for a system-generated view named Comments_Inline. You can configure the inline table there.

4 Likes

Thanks for your reply.

Here’s how I have the Comment column in AppSheet.

Thanks your reply Steve. I don’t have that view in the system views section.

Steve:

The rows of an inline table (such as the one in your screenshot) are ordered according to the inline view’s configuration,

Good point! I should have realized that. I’ll blame it on the lateness of the hour!

2 Likes

A Comment_Inline view should be generated for you automatically. I am not sure how that occurs when you are creating your row list “manually” by an expression. Maybe you need to force it to be created by accessing the view?

At the bottom right-hand corner of the inline view in your image above, There is a “View” button. While in the emulator, tap that button. It will open the view in full screen mode. Then look below the emulator view (image below) to see what view name AppSheet is using for that view. I am hoping this activity will create the “Comment_Inline” view for you. If so, then you can go to that view and apply the Sorting as @Steve has suggested.

2 Likes

Thanks again. I appreciate you guys helping me with this.

I did this and it doesn’t add an inline view. I should also mention that there is a drivers table that I did the same way, and they both have the same “View: table name” below.

Do you think it is not generating this due to it being a Virtual Column and not a regularly referenced table? As of right now we have Comments, Driver History, and Attachments.

1 Like

wrodriguez:

Do you think it is not generating this due to it being a Virtual Column and now a regularly referenced table?

Yes. The view “fastTable” is an on-the-fly view.

Probably the best solution is to use the AppSheet functionality that creates a Parent/Child relationship between your Vehicle table to your Comment table for you. This is as simple as going into your Comment table, editing the column that contains the Vehicle row key (is that Vehicle_UUID?), set that columns as a Ref column back to your Vehicle table and then turn on the “Is part of” switch in that same column.

This creates the parent/Child relationship for you, adding a Virtual Column into your Vehicle table automatically (so you can delete your manually created column) and generates the Comment_Inline view for you. Everything will look exactly like you have built - its just done for you!

For more information on the Parent/Child relationship access this article below - scroll down to " Expressing Ownership Between Tables"

2 Likes

Alright so what I did in order for this to work was create a ref table from the key [uuid] and then changed the column formula from REF_ROWS to my original SELECT statement. That now shows the DriverHistory_inline view in UX → Show System Views and allows me to customize the order of how they show by date descending. I will do the same to Comments and Attachments.

I appreciate the help guys! Glad I got this to work.

1 Like