Avaya Client SDK

< Back to Package Overview

Using Shared Contacts

Using the Avaya Client SDK, you can easily access and use shared contacts through the contacts app.

You can create new contact, update and delete existing contacts via Contacts service. Shared contacts can be added from enterprise directory providers like Microsoft Active Directory. Contacts found in enterprise directory also can be added to the contact's list.

Using the Avaya Client SDK, you can receive contact's presence. For more details see Using Presence with Shared Contacts.

Add contacts

Start adding a contact from obtaining an instance of EditableContact by calling ContactService.CreateEditableContact(). Once contact is created, all its properties will have empty values.

EditableContact editableContact = contactService.CreateEditableContact();

Next step is filling contact object with information. Once you've finished filling the contact object with information, verify that you haven't missed any of the necessary information by checking contact's EditableContact.ContactSavable property.

bool contactSavable = editableContact.ContactSavable;

If contactSavable has false value then you've missed some of the necessary contact's information. Please see EditableContact.ContactSavable documentation for details. Otherwise, if the contact is savable, next step will be checking if Add Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to add the contact.

bool addContactCapability = contactService.AddContactCapability.Allowed;
if (!addContactCapability)
{
    PrintInfo("Add contact operation is currently unavailable.");
}

If this capability is allowed, you can add the contact.

ContactService.AddContactCompletionHandler completionHandler = (arg) =>
{
    if (arg.NewContact != null)
    {
        PrintInfo("Contact has been added.");
    }
    else
    {
        PrintError(string.Format("Failed to add contact: {0}",
            arg.Error));
    }
}
contactService.AddContact(editableContact, completionHandler);

Edit contacts

Start editing a contact by obtaining an instance of EditableContact by calling ContactService.CreateEditableContactFromContact(). This function makes existing contact editable and sets writability of particular contact's properties.

EditableContact editableContact = contactService.
    CreateEditableContactFromContact(contact);

Next step is updating the contact's information.

// Set name
editableContact.FirstName.Value = "Bob";

// Create phone item as work phone
EditableContactPhoneField contactPhoneField = new EditableContactPhoneField();
contactPhoneField.PhoneNumber = "1(234)567-89-00";
contactPhoneField.Type = ContactPhoneNumberType.Work;
contactPhoneField.IsDefault = true;

// Add created phone item to editable contact
editableContact.PhoneNumbers.Values.Add(contactPhoneField);

Also, some of contact's properties might be read-only. Before attempting to edit the property, check its Write Capability.

firstNameProperty = editableContact.FirstName;
if (firstNameProperty.WriteCapability.Allowed)
    firstNameProperty.Value = "Bob";
else
    PrintInfo("First name of this contact is read-only.");

This capability should be used in 'edit contact' UI of your application to disable input fields for read-only properties.

Once you've finished updating the contact's information, verify that you haven't missed any of the necessary information by checking contact's EditableContact.ContactSavable.

bool contactSavable = editableContact.ContactSavable;

If contactSavable has false value then you've missed some of the necessary contact's information. Please see EditableContact.ContactSavable documentation for details. Otherwise, if the contact is savable, next step will be checking if Add Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to add the contact.

bool editContactCapability = contact.UpdateContactCapability.Allowed;
if (!editContactCapability) 
{
    PrintInfo("Edit contact operation is currently unavailable.");
}

If this capability is allowed, you can update this contact.

ContactService.UpdateContactCompletionHandler completionHandler = (arg) =>
{
    if (arg.UpdatedContact != null)
    {
        PrintError("Contact has been updated");
    }
    else
    {
        PrintError(string.Format("Failed to update contact:  {0}",
            arg.Error));
    }
};
contactService.UpdateContact(editableContact, completionHandler);

Delete contacts

Start deleting contact by checking if Delete Contact operation is available at the moment. Operation might be unavailable, for example, if the contacts server is temporarily down. Because of that, it's recommended to check the capability prior to attempting to delete the contact.

bool deleteContactCapability = contact.DeleteContactCapability.Allowed;
if (!deleteContactCapability) 
{
    PrintInfo("Delete contact operation is currently unavailable.");
}

If this capability is allowed, you can delete this contact.

ContactService.ContactActionCompletionHandler completionHandler = (error) =>
{
    if (error == null)
    {
        PrintInfo("Contact has been deleted.");
    }
    else
    {
        PrintError(string.Format("Failed to delete contact: {0}",
            error.Error));
    }
};
contactService.DeleteContact(contact, completionHandler);