We help IT Professionals succeed at work.

Lotus Script Issue witt names

Ray Padilla
Ray Padilla asked
Medium Priority
Last Modified: 2013-12-18
Hello experts,

Once again I am having some issues with Lotusscript, I am scheduled to take a class end of April, I am hoping it will cut down on these type questions.
Here is a script being used in one of our apps. (This was created before I came into the picture):

Sub Postopen(Source As Notesuidocument)
      Const ELUREPID = "85256A6C004C8E88"
      Dim session As New notessession
      Dim db As New notesdatabase("","")
      Dim thisdb As notesdatabase
      Dim doc As notesdocument
      Dim view As notesview
      Dim entry As notesviewentry
      Dim uname As String
      Dim sdept As String      
      Dim smanager As String
      Dim stitle As String
      Dim sphone As String
      Dim sdb As String
      Dim sserver As String
      Dim s1 As String
      Dim s2 As String
      Dim stat As String
      Dim sroles As String
      uname = session.username
      Set thisdb = session.currentdatabase
      sserver = thisdb.server
      If (source.isnewdoc) Then
            If db.OpenByReplicaID(  sserver, ELUREPID ) Then
                  Set view = db.getview("Lookup")
                  Set entry = view.getentrybykey(uname)
                  If (entry Is Nothing) Then
                        Set view = db.getview("Lookup2")
                        uname = session.commonUserName
                        Set entry = view.getentrybykey(uname)
                  End If
                  If Not(entry Is Nothing) Then
                        Set doc = entry.document
                        Call source.fieldsettext("Dept",doc.DeptTitle(0))      
                        Call source.fieldsettext("Title",doc.Description(0))
                        Call source.fieldsettext("Phone",doc.Extension(0))      
                        smanager = doc.Supervisor(0)
                        If Instr(smanager, "(") > 0 Then
                              s1 = Left$(smanager, Instr(smanager,",")-1)
                              s2 = Trim$(Mid$(smanager,Len(s1)+2))
                              smanager = Trim$(Left$(s2,Instr(s2,"(")-1)) +" "+Trim$(s1)
                              s1 = Left$(smanager, Instr(smanager,",")-1)
                              's2 = Right$(smanager,Instr(smanager,",")-2)
                              s2 = Trim$(Mid$(smanager,Len(s1)+2))
                              smanager = s2+" "+s1
                        End If
                        Call source.fieldsettext("Manager",smanager)
                  End If
            End If
            Call source.refresh
            Call source.gotofield("VPN_DateNeeded")
      End If
      If source.isnewdoc Then
            Call source.collapseAllSections
            Call source.expandAllSections
      End If
End Sub

The script populates certain fields in a form, I am figuring based on username, however the application that it is using (ELU) will not populate fileds for users who's names don't match exactly, let me explain, the ELU app uses nicknames instead of usernames, there is a field in ELU that contains the username which I imagine is how the script gets the other data but for some names it will not populate all fields. If the user name is Ray and the nick name on ELU matches then it will populate however if the username is Raymond and the nickname is Ray it will not. What I need if for this script to populate the fields even if the nickname is soemthing else. Can this be done?
Watch Question

Try this, but it's a risk to match partial names...

change the line
        Set entry = view.getentrybykey(uname)
to this:
Set entry = view.getentrybykey(uname,false)

Groupware Consultant
False is already the default value...

The code tries to find a document in the Lookup-view based on the current user's username (with format CN=John Doe/O=ACME). If there's no such document, the view Lookup2 is opened to search for the common username (like John Doe). Only if either document is found, some fields in the form are populated. That's what the code says.

Nicknames are out of the question, I'd say. The only solid information you can get are the full username and the common username. The views Lookup and Lookup2 should be designed using these usernames. Otherwise, it will never work. Unless, of course, you create an additional lookup-view to find a nickname for a username...

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Ray PadillaIT  Director


Thanks Sjef, I looked at the views and of course you are correct, now how do I make it work with an additional view with the nicknames? Or better yet how can i make it look at the username then IF there is a nickname use that instead?
Sjef BosmanGroupware Consultant

So you want to add the nicknames somewhere? In what database? There's no NotesSession.nickname available. You need therefore code like
    get the standard Lookup view
    try to find the username
    if not found then
        get the alternate Lookup2 view
        try to find the common username
        if not found then
            get the Nickname view
            find the username based on nickname
            get the standard Lookup view again
            then try to find the username just found in the Nickname view
        end if
    end if

Is that it?

Just a question: is the nickname already used everywhere in that application?? Not good... You'd better translate a nickname into a proper username already in the form, before it is saved.
Ray PadillaIT  Director


Let me get back to you on this one, I have brought this up to the managers and it seems that the nickname thing may be going away....
Sjef BosmanGroupware Consultant

Brilliant!! :-D
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.