• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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?
0
padillrr
Asked:
padillrr
  • 3
  • 2
1 Solution
 
p_parthaCommented:
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
0
 
Sjef BosmanGroupware ConsultantCommented:
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...
0
 
padillrrProject CoordinatorAuthor Commented:
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
padillrrProject CoordinatorAuthor Commented:
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....
0
 
Sjef BosmanGroupware ConsultantCommented:
Brilliant!! :-D
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now