/ Forums / Advansys Formativ / Creating Solutions with Formativ / Zombies: Undelete-able address book entries

  • Creator
    Topic
  • #3927
    emsegal
    Participant

    I am trying to clean out an address book programatically. I have code like this:

    dim objBook
    set objBook=addressbooks.item(addressbooknumber)
    j=0
    do until objbook.count < 1
    objbook.item[j].delete
    j=j+1
    Loop
    set objbook=nothing
    endsub

    However, this does not work. It seems to delete some entries, but not others. It does not delete the organizational entries that are automatically added when someone adds a person, and it does not delete entries with an email but no name.

    For example, if I add:

    name: John Smith
    company: IBM Corp
    email: JSmith@ibm.com

    and
    name:
    company:
    email: xyz@abc.com

    There will be 3 entries in the address book: one for John Smith, one for IBM, and one for xyz@abc.com. If I run the code above, only the first one will be deleted. After that, objbook.count=0 so the program thinks it is done and quits.

    I tried changing the code to the following:

    dim objBook
    set objBook=addressbooks.item(addressbooknumber).object.addressbookentries
    j=0
    do until objbook.count < 1
    objbook.item[j].delete
    j=j+1
    Loop
    set objbook=nothing
    endsub

    to use the Groupwise addressbook object but that produced identical results. Can you tell me how I can kill off these “zombie” address book entries? Thanks.

  • Author
    Replies
  • #6627
    Support 1a
    Participant

    You generally need to work backwards when deleting items from a collection. Starting from the beginning, the value of Count decreases after each delete, resulting in some items being left over.

    The following code should do what you want:

    Sub Main(Client, GWEvent)
    
         Dim objAddressBooks
         Dim objAddessBook
         Dim objAddressBookEntry
         Dim iCount
         Dim x
    
    
         ' Get the address books object
         Set objAddressBooks = GroupWise.Account.AddressBooks
    
    
         ' Locate the address book called "Test Account"
         Set objAddressBook = objAddressBooks.Item("Test Account")
    
         
          iCount = objAddressBook.AddressBookEntries.Count
         
         for x = iCount to 1 step -1
          set objAddressBookEntry = objAddressBook.AddressBookEntries.Item(x)
          objAddressBookEntry.Delete
         next
         
         
         Set objAddressBooks = nothing
    
      
    End Sub
    

    Advansys Support

    #6628
    emsegal
    Participant

    Thanks, but that did not solve the problem. First, I think there were some errors in your code: AddressBookEntries is not a property of AddressBook.I got an error when I ran the code as you wrote it, so I changed it as follows:

    Sub Main(Client, GWEvent)

    Dim objAddressBooks
    Dim objAddessBook
    Dim objAddressBookEntry
    Dim iCount
    Dim x

    ‘ Get the address books object
    Set objAddressBooks = GroupWise.Account.AddressBooks

    ‘ Locate the address book called “Test Account”
    Set objAddressBook = objAddressBooks.Item(“Test Account”)

    iCount = objAddressBook.Count

    for x = iCount to 1 step -1
    set objAddressBookEntry = objAddressBook.Item(x)
    objAddressBookEntry.Delete
    next

    Set objAddressBooks = nothing

    End Sub

    This ended up having the same problem: it deletes the “normal” address book entries with a name and an email address, but it does not ignore the entries that either
    a) have a name and no email address, or
    b) are an entry for an organization only.
    I can delete these manually, but I need to find a way for my program to do it.

    If it would help, my system is on VNC, (like PCAnywhere) and you could take a look at what I am talking about. Thanks,

    Eric

    #6626
    Support 1a
    Participant

    Eric,

    A couple of us here have independently confirmed that the example code we posted does work. What were the exact errors you received when you ran our example code as-is?

    AddressBookEntries is a property of the Object API AddressBook object. Here’s a link to the official Novell documentation for the AddressBook object:

    Address Book Object documentation

    Unfortunately, we could not get your code to run. The Object API AddressBook object does not have a count property. Is it possible the code you have posted is not exactly the same code as you are running? Formativ provides two ways to access the address books:

    1) Via the wrapped address book objects exposed via the GroupWise.AddressBooks property. I suspect this might be the object you are referring to, as the AddressBook object exposed from here does have a Count property. However, this is not the object set our example code is using.

    2) Via the native Object API, which is exposed via GroupWise.Account.AddressBooks. This object set is actually the native GroupWise Object API, and does have an AddressBookEntries property. This is the object our example code is using.

    Regards,

    Advansys Support

    Thanks,

    Advansys Support

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