Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Agent to check docs against other docs in NAB

Status
Not open for further replies.

DoctorGonzo

Programmer
Jan 23, 2004
48
0
0
GB
Hi All,

I don't know if someone can help me or provide a code snippet or something.

I have a database called people.nsf, which contasins a document called user.

What I want to do is create an agent that checks each USER document in PEOPLE to see if it there is a PERSON document in NAMES.NSF (our address book)... and if the user is not in the address book to delete the corresponding USER record in PEOPLE.NSF...

has anyone done this before? can anyone point me in the right direction? The common field in both databases on both documents is the hierarchical user name.

I think LotusScript (at which I am no expert) is the correct solution for this...

Any help much appreciated - couldn't find anything really in the sandbox

Many thanks all

Gonzo
 
LotusScript is your only solution, and it is not all that difficult.
First, you need code to iterate through all your docs in your People db. There's two ways of doing that : either you go through all docs in the database, or you have a view that lists the docs you want and you iterate through that - which eliminates a portion of useless checks on docs that do not concern you.

Going for the second way (seems quite feasible, after all, you need views, right ?), the iterate code would be like this :
Code:
dim session as new notessession
dim db as notesdatabase
dim view as notesview
dim doc as notesdocument
dim olddoc as notesdocument

set db = session.currentdatabase
set view = db.getview("[i]viewname[/i]")
set doc = view.getfirstdocument
do while not(doc is nothing)
   ...
   set olddoc = doc
   set doc = view.getnextdocument(olddoc)
   delete olddoc
loop

So, we have our iteration procedure. Now, for each document, you want to check the names.nsf for the corresponding People document. First thing : do you have the proper hierarchical name in you people db ? It's a lot simpler if you do. Since I'm lazy, I will assume that is the case ;-).
So, assuming you have the same name format in both dbs, we need to do the following :
- declare and open the names.nsf
- get the right view for our lookup
- use the view in our iteration code

The declaration can be made before iterating, makes more sense like that. Just one thing, we want to be sure that the names.nsf is available before going forward, so we make the check like this :
Code:
dim servernab as notesdatabase
   dim nabview as notesview
   dim nabdoc as notesdocument

set servernab = session.getdatabase(db.server,"names.nsf")
if servernab.isopen then
   set nabview = servernab.getview("($PeopleLookup)")
   ...
end if

So, here we have code that declares the names.nsf db and, if available, gets the associated People view we need.

Finally, we want to check if the doc in the People.nsf corresponds to a Person doc in the names.nsf.
To do that, I'll suppose that both docs have a field containing the name in full hierarchical format. We can then use the name in the doc in the Person db to do the lookup in the serve NAB. If we find a document, it follows that we have a match.
Code:
dim username as string

username = doc.fullname(0)
set nabdoc = nabview.getdocumentbykey(username,true)
if not(nabdoc is nothing) then
   'we have a match !
end if

Now, if we put all this together, we get :

Code:
dim session as new notessession
dim db as notesdatabase
dim servernab as notesdatabase
dim view as notesview
dim nabview as notesview
dim doc as notesdocument
dim olddoc as notesdocument
dim nabdoc as notesdocument
dim username as string

set db = session.currentdatabase
set servernab = session.getdatabase(db.server,"names.nsf")
if servernab.isopen then
   set nabview = servernab.getview("($PeopleLookup)")
   set view = db.getview("[i]viewname[/i]")
   set doc = view.getfirstdocument
   do while not(doc is nothing)
      username = doc.fullname(0)
      set nabdoc = nabview.getdocumentbykey(username,true)
      if not(nabdoc is nothing) then
         'we have a match !
      end if
      set olddoc = doc
      set doc = view.getnextdocument(olddoc)
      delete olddoc
   loop
end if

Of course, if there is a match, you need to decide what to do. I'll leave that up to you for now :).

Pascal.
 
Pascal,

Thank you once again!!

I shall give this a go and let you know the results!

Gonzo :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top