/ Forums / Advansys Formativ / Creating Solutions with Formativ / Home Address
-
CreatorTopic
-
December 12, 2005 at 8:37 am #4193
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
-
CreatorTopic
-
AuthorReplies
-
December 12, 2005 at 2:13 pm #7445
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 oFieldset oBook = groupwise.account.addressbooks.item(“Test”)
set oEntry = oBook.addressbookentries.item(1)
for each oField in oEntry.Fields
msgbox oField.name & vbcrlf & oField.value
nextset oEntry = nothing
set oBook = nothingIf 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 oFieldset 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.Valueset oEntry = nothing
set oBook = nothingHope this helps.
MADecember 12, 2005 at 2:25 pm #7439Thanks MA.
Advansys Support
December 13, 2005 at 6:29 am #7438Thanks MA, that works a treat!
John
December 13, 2005 at 6:54 am #7443Actually, I seem to have spoken too soon

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
December 13, 2005 at 1:46 pm #7442quote:
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 oFieldset 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 ifset oEntry = nothing
set oBook = nothingThanks
MADecember 13, 2005 at 2:15 pm #7441Thanks 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
December 14, 2005 at 2:53 am #7440Superb, thanks for all your help.
John
December 16, 2005 at 2:33 am #7446Please 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
December 18, 2005 at 2:46 pm #7444The 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
-
AuthorReplies
- You must be logged in to reply to this topic.