What would be the best way to, from the action bar in one NSF, get the next value from a second NSF? I am trying to assign purchase order numbers.
If it's just a sequential number, (say you have a series of purchase orders, all in sequence, from 001 to 999), and you want the next "available" PO number from the "pool", here's one solution: Grab the view and read the value of the last PO document (assuming the view is sorted by PO number) number, and then increment one.
This code should work fine on Notes 5 or higher - it won't work on 4.x because of two places in the code. I didn't write any test databases and run any tests on this code, but it should work (plug in your own database, view and field names). In any case, it should get you going in the right direction.
Dim nsCurrent As New NotesSession Dim ndbLookup As NotesDatabase Dim nvecLookup As NotesViewEntryCollection Dim nvLookup As NotesView Dim nveLookup As NotesViewEntry Dim ndLookup As NotesDocument Set ndbLookup = nsCurrent.GetDatabase("myPODB.nsf", False) If Not ndbLookup Is Nothing Then Set nvLookup = ndbLookup.GetView("myPOLookupView") If Not nvLookup Is Nothing Then Call nvLookup.Refresh() nvLookup.AutoUpdate = False Set nvecLookup = nvLookup.GetAllEntries Set nveLookup = nvecLookup.GetLastEntry If Not nveLookup Is Nothing Then Set ndLookup = nveLookup.Document End If End If End If Print "The last PO Number Recorded was " & ndLookup.PONum(0)
Here's how the code works:
* First, we dim all the object variables, of course.
* Next, we get a handle to the lookup database (you said it was in a separate NSF from the one in which this 1code is running, although it could be the same DB, if you wanted it to be - the rest of the code doesn't care). The second parameter is new to Notes 5 - if it is omitted or set to True, then the DB object will be created whether the database can be opened or not. If you omit this one or set it to true, you will need to put another line of code in there to see if you can open the database. So I just put in the False so that it works like 99% of the other objects - if it can't find it, or open it, it sets the object variable (in this case ndbLookup) to Nothing.
* Then we get the view object which should be a view which is sorted by PO Number.
* Then we get the ViewEntryCollection of the elements of the view. Note that this is different from a document collection. A DocumentCollection object, when created from a view or FTIndex, sorts its elements in the order in which the documents were created in the database (officially, the sort order is "undefined"). The only way to get them in the correct order (matching the view sort order), is to get the EntryCollection. This is new to Notes 5, as well.
* Once we have the view entry collection, we just get the last entry (which should be the highest numbered PO), and get it's Document object. You could sort the view Descending and get the first document object, but that's personal choice, I think.
Dig Deeper on Domino Resources - Part 5
Related Q&A from Todd Fuder
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.