Hi,

I'm running some test applications against the addressbook. I have added a custom field to the fierld definitions like so:

If (objAddressbook.ObjType = AddressBookTypeConstants.egwNovellPersonal) Then
If Not (FieldDefined(objAddressbook, m_strCustomField)) Then
CreateDefinedField(objAddressbook, m_strCustomField)
End If
End If

I've included the functions that validate the field existance and create the field.

Once the field definition is created and i've added the custom field to all the address book entries, i need to remove them for testing purposes. When attempting to delete the fields from the addressbookentry I get an error indicating "An invalid argument was passed in the function call."

What i'm finding odd is that i am using the name of the custom field to retrieve the field object. Oince i have the field object i use the delete method of the object and that's when i get the error. Seems very straneg to me. I have tried to mothids and they both fail. Here are both methods.


Can anyone, tell me why i'm getting this error and how I can delete these fields programmatically?

I appreciate any help on this one thanks.

Here is the code:

METHOD 1:
Try

' retrieve the addressbook entry
objEntry = objEntries.Item(index)

' look for the custom field
For j As Integer = 1 To objEntry.Fields.Count
If objEntry.Fields.Item(j).Name = m_strCustomField Then
Try
objEntry.Fields.Item(j).Delete()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Exit For
End If
Next

Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

METHOD 2:
Try

' retrieve the addressbook entry
objEntry = objEntries.Item(index)

' look for the custom field
For j As Integer = 1 To objEntry.Fields.Count
If objEntry.Fields.Item(j).Name = m_strCustomField Then
Try
Dim objField as Field2 = objEntry.Fields.Item(j)
objField.Delete()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Exit For
End If
Next

Catch ex As Exception
Console.WriteLine(ex.Message)
End Try


Private Function FieldDefined(ByVal objAddressbook As AddressBook2, ByVal strFieldName As String) As Boolean

Dim objFieldDef As FieldDefinition2
Dim objFieldDefs As FieldDefinitions = objAddressbook.FieldDefinitions

Try
objFieldDef = objFieldDefs.Item(strFieldName, FieldTypeConstants.egwString)
If Not (objFieldDef) Is Nothing Then
Return True
End If

Catch
Return False
End Try

End Function

Private Sub CreateDefinedField(ByVal objAddressbook As AddressBook2, ByVal strFieldName As String)

Dim objFieldDef As FieldDefinition2
Dim objFieldDefs As FieldDefinitions = objAddressbook.FieldDefinitions

Try
objFieldDef = objFieldDefs.Add(strFieldName, FieldTypeConstants.egwString)

Catch
End Try

End Sub