i have problem in sorting a returned document collection. i am using getalldocumentbykey to get the document collection. Can any body help me to sort out this problem. I have to sort the document collection based on date and time for eg
If the column contains date/time values, the key has to be a date/time as well. See e.g. the LotusScript TimeValue function.
At least this proves, that your dates are stored as text and that’s why the sorting will not always be correct.
Anyway, even if you get the view to sort correctly, using GetAllDocumentsByKey() will not solve your problem, as it returns an unsorted collection. Or more exactly: The exact order is undefined. GetAllEntriesByKey otoh does return a sorted collection of ViewEntries. Plus it provides highly efficient access to the values in this column via its ColumnValues property.
Could you use a NotesViewEntryCollection instead of the document collection? If the view is sorted already (it should be, if you use real date fields and not text fields), the viewentry collection will retain that sorting.
From Designer help:
“The methods and properties in NotesViewEntryCollection are the same as those for NotesDocumentCollection, except for IsSorted, because this property is always True for NotesViewEntryCollection.”
Hi thanks for your response, but how can i sort the view based on date/time field. If i sort the documents, they are sorted based on date. but not on time.
Again, make sure, that the dates are really stored in a date item, not a text item. Set the column properties to either sorted descending or ascending as you need it. On the advanced format tab you could specify the Style as Date/Time, but that’s just for visuals.
Should it turn out, that your date-time-values are stored as text indeed, you might get away - temporarily - with a column formula like
@ToTime(YourFieldName)
This will work - and would correct potential sorting issues caused by text items - if the date format is always set to american format on any machine involved, but still you should consider to switch to the correct field type and update all documents.
Well, only IF this should turn out to be the problem, of course.