Modify code to populate fields

Posted on 2006-03-23
Last Modified: 2013-12-18
Hey Experts!

I have some script that I need to modify but am having a little trouble with it, here's the code:

Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim view As notesview
      Dim doc As notesdocument
      Dim ldoc As notesdocument
      Dim db As notesdatabase
      Dim wstring As String
      Dim sarray(0) As String
      Set uidoc = ws.currentdocument
      Set doc = uidoc.document
      Set db = doc.ParentDatabase
      If Trim$(uidoc.fieldgettext("skey")) <> "" Then
            Set view = db.getview("AELFNAME")
            sarray(0) = uidoc.fieldgettext("skey")
            Set ldoc = view.getdocumentbykey(sarray,True)
            Call uidoc.fieldsettext("x_empno",ldoc.employeeid(0))
            Call uidoc.fieldsettext("x_lastname",ldoc.lastname(0))
            Call uidoc.fieldsettext("x_firstname",ldoc.firstname(0))************
            Call uidoc.fieldsettext("x_jobtitle",ldoc.title(0))
            Call uidoc.fieldsettext("x_phone",ldoc.extension(0))
            Call uidoc.fieldsettext("x_deptno",ldoc.deptno(0))
            Call uidoc.fieldsettext("x_deptname",ldoc.deptTitle(0))
            Call uidoc.fieldsettext("x_supervisor",ldoc.supervisor(0))
            Call uidoc.fieldsettext("x_superempno",ldoc.superEmpno(0))
            Call uidoc.fieldsettext("x_deptabbr", ldoc.deptabbr(0))
      End If
End Sub

What I need is to populate the x_firstname field with the nick name if it exist if not then populate it with the firstname, I know that in formula I can do it by virtue of @IF (nickname = "", firstname ; nickname) which works great in a view but how do I do this in this script?
Question by:padillrr
    LVL 63

    Expert Comment

    if ldoc.nickname(0))="" then

      Call uidoc.fieldsettext("x_firstname",ldoc.firstname(0))
     Call uidoc.fieldsettext("x_firstname",ldoc.nickname(0))
    ENd IF

    I hope this helps !


    Author Comment

    I get an error on the first line of your code

    if ldoc.nickname(0))="" then ************HERE! I placed the code under this line :Call uidoc.fieldsettext("x_lastname",ldoc.lastname(0))

      Call uidoc.fieldsettext("x_firstname",ldoc.firstname(0))
     Call uidoc.fieldsettext("x_firstname",ldoc.nickname(0))
    ENd IF
    LVL 63

    Accepted Solution

    remove the extra )

    if ldoc.nickname(0)="" then

    Author Comment

    I missed that as well it works great thanks!
    LVL 46

    Expert Comment

    by:Sjef Bosman
    Just a suggestion: try to work with fieldgettext and fieldsettext as little as possible. Use NotesDocument.GetItemValue and NotesDocument.ReplaceItemValue instead.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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…
    IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    745 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