Link to home
Start Free TrialLog in
Avatar of Ray Padilla
Ray PadillaFlag for United States of America

asked on

Lotus Script Issue witt names

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)
                        Else
                              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
      Else
            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?
Avatar of p_partha
p_partha

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)

Partha
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ray Padilla

ASKER

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?
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.
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....
Brilliant!! :-D