How update a person document in the Domino Directory based on form input

I have restricted access to our Domino Directory so that users only have "Reader" access.  However, I want the users to be able to update their contact information on the "Work" tab of their person documents.  I would like to create a form listing the fields on "Work" tab of the person document and provide this form to the users in a database.  

How can I accomplish the following:
1.  When the user creates a document using the form, automatically populate the fields with the current values in the user's person document and allow certain users to change this information on behalf of another user.
2.  After the user makes changes to the field values, save and close the document then have an agent run against these documents and update the users' person document in the Domino Directory using the "Employee ID" as the key.

I am a beginner using Lotusscript so any code you can provide would greatly appreciated.
Who is Participating?
I would recommend creating a simple database with a sinlge form where users post their requests.  Once a request has been created in the database, a background agent will update the documents in the NAB, then delete the request document.  Madheeswar's agent above should do the trick.  Just be sure to add a line that deletes the request document (or mark it processed like SysExpert recommends, but your database will continue to grow if you leave them in there).

Most users will only need only depositor access since this database will not contain any documents except those that have not yet been been processed by the backend agent.

The form needs to contain a field to identify the user (Editable for priveleged users, computed when composed for standard users) and any other fields that you want the user to be able to update.

Here's how I would code the agent.  This example should work, but you will need to supply your own settings and add error handling.

      Dim sess As New NotesSession()
      Dim db As NotesDatabase
      Dim nab As New NotesDatabase("", "")
      Dim view As NotesView
      Dim dc As NotesDocumentCollection
      Dim docRequest As NotesDocument
      Dim docNext As NotesDocument
      Dim docPerson As NotesDocument
      Const NAB_SERVER_NAME = "Server1/Acme"
      Const NAB_FILE_NAME = "names.nsf"
      Set db = sess.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      If (dc.Count = 0) Then Exit Sub
      If Not nab.Open(NAB_SERVER_NAME, NAB_FILE_NAME) Then Error 2000, "Unable to open the Domino Directory."
      Set view = nab.GetView("($Users)")
      Set docRequest = dc.GetFirstDocument()
      Do While (Not docRequest Is Nothing)
            Set docNext = dc.GetNextDocument(docRequest)
            Set docPerson = view.GetDocumentByKey(docRequest.GetItemValue("UserName")(0), True)
            If (docPerson Is Nothing) Then
                  ' Need to add error handling here.
                  ' Here is where you update the Person document.
                  docPerson.PhoneNumber = docRequest.GetItemValue("PhoneNumber")(0)
                  ' Continue updating the fields here...
                  Call docPerson.Save(True, False)
            End If
            Call docRequest.Remove(True)
            Set docRequest = docNext

Below is the agent which u need to schedule. Sign the agent with Admin id.
Dim s As New NotesSession
      Dim view As notesView, currview As notesview
      Dim queue As notesDocumentCollection
      Dim keyValue As String, dataValue As String
      Dim src As notesDocument, target As notesDocument
      Dim here As notesDatabase
      Dim there As New NotesDatabase("servername","path\filename.nsf") 'Give your NAB details
      Set view = there.getView("name of some view that sorts on key value")
      Set here = s.currentDatabase
      Set currview= here.GetView("name of some view ")
      Set src = currview.getFirstDocument
      Do Until src Is Nothing
            keyValue = src.getItemValue("name of some field containing the key value")(0)
            'dataValue = src.getItemValue("name of some field containing the value to copy")(0)
            Set target = view.getDocumentByKey(keyValue)
            If Not target Is Nothing Then
                  target.replaceItemValue "name of field to change" , dataValue
                  target.Save True , True
            End If
            Set src = currview.getNextDocument(src)
madheeswar has great code, but it may be missing some stuff.

1) You need a field with a status so that the agent only updates the changed docs in your database.
2) the section
 'dataValue = src.getItemValue("name of some field containing the value to copy")(0)
            Set target = view.getDocumentByKey(keyValue)

needs to be repeated for all the fields you want to update.

The view used should oly have changed docs, and use the status field to determine that, ie everytime a change is made, the status is changed to "updated", and when the agent is run it is either set to "" or "closed".

I hope this helps !
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

FYI to all: No need to "schedule" this.  Instead, have the agent RunOnServer.  It can check the signature of the saved document to verify that the owner or an admin has made the edits, then apply the changes in real time. You can even have the editor DB switch the user to viewing his own Person document in the NAB when done, for instant feedbacl and gratification.

Nice, no?
FYI Pt 2: RunOnServer will work asuming the users are working from the server.  If they are working from a local replica, it will not.
niccilawAuthor Commented:
I am working on implementing your proposed solutions, but I was wondering if you all thought the code should have a way to compare the old person document values with the new ones?  In the form I created, I have a table where the current person document information is displayed on one side and the user can input changes to their person document on the other side.  I tried modifying the code to include a way to compare the values, but I cannot figure out how to compare two variants or convert them to a string so I can compare them.
Why is a compare needed ?

If you populate the fields with the original data, and then update the person doc with new data, why is a comparison needed anywhere ?

niccilawAuthor Commented:
I just did not want the code rewriting information that has not changed. Maybe I am overthinking this.  One more thing, one of the fields contains an attachment.  How can I modify the code to update the attachment?  
SInce this  Q has already been answered and closed, I would suggest opening a new Q for this.

1) All teh values from fiels on both sides will be in arrays, you need to (typically) compare element zero of both sides

2) Notes is pretty efficient about the procesisng of changed and unchanged values, so it is probably not necessary

3) You can do it with attachments as well, but that will probably need a bit more specific coding

4) SysExpert is correct, any additional stuff is probably more approapriate in a new Q, but don't sweat that too much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.