@sort in lotus script

Is there a way to access the @sort function in lotus script? I am trying to make an agent that sorts a view by a certain column and when it finishes I want it to print whatever column it was just sorted by. Thanks for suggestions ahead of time.

Subject: @sort in lotus script

I’m not really certain what you want to do. @Sort is used to sort lists, not views. Are you wanting to visibly (in the UI) programmatically resort a view using a different column than the one specified in the view design? Or do you want an agent that runs in the background to get a specific column of the view, sort the values in that column, and then print out the resulting “list”?

If it’s the second one, you could do it - maybe.

You’d have to loop through the view, adding the column value for each record to an array. Then you’d have to sort the array and print out the result. There are a lot of threads here that deal with sorting arrays; here’s a function I found a while ago that works well (for alphabetical sorting; you’d have to search if you want another kind):

Function SortArray (TheArray As Variant) As Variant

'simple alphabetical array sorter, note the sort is case insensitive

'Chuck Floyd, 26-Mar-2003

Dim tstr As String

Dim j As Integer, i As Integer

Dim values As Variant

If Isarray(TheArray) Then ’ we can only sort the variant if its an array

values = TheArray

For i = Lbound(TheArray) To Ubound(TheArray) - 1

For j = Lbound(TheArray) To Ubound(TheArray) - 1

If Strcompare(values(j), values(j + 1), 5) > 0 Then ’ 5 = case/pitch insensitive

tstr = values(j)

values(j) = values(j+1)

values(j + 1) = tstr

End If

Next

Next

SortArray = values

Else 'return the starting value since its not an array

SortArray = TheArray

End If

End Function

Subject: RE: @sort in lotus script

I am trying to do the first one. I want to press an action button that programmatically resorts the view depending on a column that is programmed in the button. I am trying to keep from making a bunch of views with different view selection formulas in them.

Any suggestions?

Subject: RE: @sort in lotus script

Now, you just added a requirement - you don’t want to make views with different view selection formulas. That’s something completely different, and has nothing to do with sorting. Are you wanting to have a single view (in other words, the columns always stay the same), but have the button filter the documents based on which button is clicked? For example, if you have a view of Help Desk Tickets, you want the user to be able to click a button that says, “show only active tickets” or “show only completed tickets” and have the view filter out only documents with the indicated status? If so, check out the NotesView.SelectionFormula method - this lets you change the selection formula programmatically.

Subject: RE: @sort in lotus script

Ok…I researched what you gave me and here is what I came up with:

Sub Initialize

Dim ws As New NotesUIWorkspace

Dim uiview As NotesUIView

Dim view As NotesView

Dim formula As String

Dim formula2 As String

formula = "SELECT @All"

Set uiview = ws.CurrentView

Set view = uiview.View

view.SelectionFormula = formula

Call ws.ReloadWindow( )

formula2 = "SELECT s_cdate != ''"

view.SelectionFormula = formula2

Call ws.ReloadWindow( )

End Sub

It puts select @all formula in the view selection then refreshes to get all the documents. Then it puts the formula I want in view selection and refreshes. The code works, however I want to put a print statement at the end to output what type of view you are looking at. The last line of code “Call ws.ReloadWindow( )” is overriding that statement. I tried running it through an agent, but it gave me an error saying can’t refresh frame then a box pops up saying my log will be shut down due to errors, which it does. Any suggestions?

Subject: RE: @sort in lotus script

What you’re doing is a really bad idea. It may seem to work OK in your little test database, but in a database with any significant number of documents the performance will be really poor.

Seriously, if you were working for me, and you designed an application this way, I would fire you. I’m not kidding.

The idea of a view index is to prevent having to examine each document every time the view is used to see whether it should appear in the view. Each time the view is used, only documents created or changed since the last use are considered for re-indexing. When you change the selection formula, you discard that index; the next time the view is used, all documents must be examined to see whether they belong in the view. And you change the selection formula twice. You’re going to make the user wait twice while the server check every document in the database to see whether it should appear in that view and if so, in what position. And users will be doing this all the time, completely bogging down the server. Furthermore, if it’s a shared view, users will interfere with each other by changing the view design among your alternatives while other users are still using the view.

Furthermore, for this to work, users will all have to have Designer access to the database. This is a recipe for disaster, as they can then modify any and all design elements. You lose all control of the design of your application.

Can you explain why you feel this is preferable to just having multiple views like any normal Notes application? You realize you can set columns to sort based on the user clicking the column heading, right? You realize that if the user is doing something (click an action, whatever) that executes your agent, whatever they do can just as well instead trigger switching to another, already existing view?

Subject: RE: @sort in lotus script

I choose to go this route b/c a lot of the action buttons I am creating have to do with multiple forms/views at once, so to lessen confusion for the user, I tried to display the chosen view that way. Obviously, from your responce, going back to making multiple views would be the best idea. Setting columns to sort based on the user clicking them is a good idea, however it is obsolete due to the what I am trying to what I have to make the button do. When I press the button, it needs to do this basically:

"SELECT * FROM username.database

WHERE (complete_date is not null) order by name"

I know there is a way to this in Lotus Script, however it prints the results in the status bar. I need it to print them onto the view. Maybe that will give you a better description as to why I thought to go that way.

As far as the last question goes, no I didn’t, and I will keep that in mind.

Subject: Nvr Mind

Ignore the last statement about translating the sql to lotus script. I made a new view, put this select statement in it, and told it to sort itself by the name column by default. Thanks for the other info. I will use it in the future.

SELECT s_cdate != “”