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

Posted on 2007-08-09
Last Modified: 2013-12-18
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.
Question by:niccilaw
    LVL 19

    Assisted Solution

    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)
    LVL 63

    Assisted Solution

    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 !
    LVL 22

    Accepted Solution

    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

    LVL 31

    Expert Comment

    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?
    LVL 22

    Expert Comment

    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.

    Author Comment

    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.
    LVL 63

    Expert Comment

    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 ?


    Author Comment

    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?  
    LVL 63

    Expert Comment

    SInce this  Q has already been answered and closed, I would suggest opening a new Q for this.

    LVL 31

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
    This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now