Lotus Script Issue witt names

Posted on 2006-03-28
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?
Question by:padillrr
    LVL 14

    Expert Comment

    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)

    LVL 46

    Accepted Solution

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

    Author Comment

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

    Expert Comment

    by:Sjef Bosman
    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.

    Author Comment

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

    Expert Comment

    by:Sjef Bosman
    Brilliant!! :-D

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

      In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
    Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now