• Creator
    Topic
  • #4193
    jyeomans
    Participant

      Hi,

      I am trying to obtain the Home Address for a contact from the Groupwise Address Book object, but am having no luck.

      Any help would be appreciated.

      Regards

    • Author
      Replies
    • #7445
      MA
      Participant

        You can access the Home Address value from the address book entries fields collection. The code below shows available fields and the value of an address book entry.

        dim oBook
        dim oEntry
        dim oField

        set oBook = groupwise.account.addressbooks.item(“Test”)

        set oEntry = oBook.addressbookentries.item(1)

        for each oField in oEntry.Fields
        msgbox oField.name & vbcrlf & oField.value
        next

        set oEntry = nothing
        set oBook = nothing

        If you know the name of the field then you can also obtain the value using the Item() method of an address book entry. See the Object API AddressBookEntry object for more information.

        dim oBook
        dim oEntry
        dim oField

        set oBook = groupwise.account.addressbooks.item(“Test”)

        set oEntry = oBook.addressbookentries.item(1)

        set oField = oEntry.Fields.Item(“Home Address”, fgwString)
        msgbox oField.Name & vbcrlf & oField.Value

        set oEntry = nothing
        set oBook = nothing

        Hope this helps.
        MA

        #7439
        Support 1a
        Participant

          Thanks MA.

          Advansys Support

          #7438
          jyeomans
          Participant

            Thanks MA, that works a treat!

            John

            #7443
            jyeomans
            Participant

              Actually, I seem to have spoken too soon Frown

              It works OK if the Home Address field in the address book contains a value, but throws an “Index out of range” error if it is empty.

              Any ideas?

              Thanks again

              John

              #7442
              MA
              Participant

                quote:


                It works OK if the Home Address field in the address book contains a value, but throws an “Index out of range” error if it is empty.


                Address book entry fields collection will not contains the field if the value is empty. You need to place an error handling to check the field existance prior to access the value.

                dim oBook
                dim oEntry
                dim oField

                set oBook = groupwise.account.addressbooks.item(“Test”)

                set oEntry = oBook.addressbookentries.item(1)

                on error resume next
                set oField = oEntry.Fields.Item(“Home Address”, fgwString)

                if not oField is nothing then
                msgbox oField.Name & vbcrlf & oField.Value
                end if

                set oEntry = nothing
                set oBook = nothing

                Thanks
                MA

                #7441
                Support 1a
                Participant

                  Thanks MA.

                  As MA mentioned, this is the way the GroupWise Object API works. If a value is not present, the Field object does not exist (presumably to save space). You always need to check if a field actually exists before accessing it.

                  Advansys Support

                  #7440
                  jyeomans
                  Participant

                    Superb, thanks for all your help.

                    John

                    #7446
                    jyeomans
                    Participant

                      Please forgive me, but I am relatively new to the Groupwise API.

                      The above code works well, but I have another query.

                      The example code above uses “addressbookentries.item(1)” to reference an entry in the selected address book.

                      My code enumerates the selected address book and populates a listview with the resulting contacts.

                      I have then tried to access individual contacts using your method by changing the items index like this: “addressbookentries.item(n)”

                      This does not work however, and if i use any number other than 1, i get an “index out of range” error. I have 2 entries in the selected address book, and i have tried numbers from 0 to 2.

                      I wonder if you could tell me where I may be going wrong?

                      Thanks again for your help so far.

                      John

                      #7444
                      Support 1a
                      Participant

                        The GroupWise Object API (which is what you are using here via Formativ) tends to expose collections using ‘1’ based arrays. This means the first entry has an index of 1.

                        I would suspect then, that you should be able to access the entries using ‘1’ and ‘2’.

                        Are you sure you are using the same book, and that the addressBookEntries collection is current?

                        Don’t forget a ListBox uses ‘0’ based arrays, so the first item has an index of 0, the second 1, etc. You may need to take this into account.

                        Advansys Support

                      Viewing 9 replies - 1 through 9 (of 9 total)
                      • You must be logged in to reply to this topic.