Problem solve Get help with specific problems with your technologies, process and projects.

Update all docs in a view without using a loop

Is there any efficient way to update all of the columns in a view to a certain value without using a loop? Also, is there any way to retrieve only the record with the biggest value in a column? Like what the keyword MAX() does in an SQL statement.
I'm going to assume you mean all of the documents in a view, not all of the columns. Probably the most efficient way is to use LotusScript, and call the NotesViewEntryCollection.StampAll method. To update all the entries in a view, for instance, you might write:
Set view = db.GetView("viewname")
Set entrycoll = view.AllEntries
Call entrycoll.StampAll("fieldname", value) 

However, if you're updating more than one field, it probably is more efficient to iterate through the documents using view.GetFirstDocument and GetNextDocument. Use view.AutoUpdate to prevent the view index from being updated while you do your loop; if you delete documents, your loop should pre-fetch the next document at the top of the loop.

If the column is the first sorted column in the view, they you can easily find the largest one using view.GetFirstDocument or GetLastDocument (depending whether the sort is ascending or descending).

Otherwise, the quickest way to iterate through a view looking for the maximum value is to use an entrycoll variable, as shown above, and iterate thru the rows examining the ColumnValues property. Using a view that's already sorted is a lot faster, so it might be worth while to have a hidden view with this sort, if for no other reason.

Macro language does not offer an efficient way to do either of these tasks. While @Max(@DbColumn(...)) will work in some cases, you still have to retrieve all the data in a column, and there's a limit to how much data @DbColumn can return.

Do you have comments on this Ask the Expert question and response? Let us know.

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...