# Display Contact List

## Goal

Read contacts from the device and display all contact names in a UI list.

## Actions Required

| Action                                  | Purpose                            |
| --------------------------------------- | ---------------------------------- |
| AddressBookReadContacts                 | Fetch contacts from device         |
| AddressBookGetReadContactsSuccessResult | Get contact count for loop         |
| AddressBookGetContactInfo               | Extract individual contact details |

## Variables Needed

* contactCount (Int)
* contactIndex (Int) = 0
* firstName (String)
* lastName (String)
* fullName (String)
* phoneNumbers (Array: String) - PlayMaker Array (set element type to String)
* emailAddresses (Array: String) - PlayMaker Array (set element type to String)

## Implementation Steps

### 1. State: ReadAllContacts

**Action:** AddressBookReadContacts

* **Inputs:**
  * limit: 0 (read all)
  * offset: 0
  * mustIncludeName: true
  * mustIncludePhoneNumber: false
  * mustIncludeEmail: false
* **Events:**
  * successEvent → GetCount
  * failureEvent → ShowError

### 2. State: GetCount

**Action:** AddressBookGetReadContactsSuccessResult

* **Outputs:**
  * contactCount → contactCount variable
* **Transition:** Set contactIndex = 0, go to LoopStart

### 3. State: LoopStart

**Logic:** Int Compare

* If contactIndex < contactCount → GetContactDetails
* If contactIndex >= contactCount → Complete

### 4. State: GetContactDetails

**Action:** AddressBookGetContactInfo

* **Inputs:**
  * contactIndex → contactIndex variable
* **Outputs:**
  * firstName → firstName
  * lastName → lastName
  * fullName → fullName
  * phoneNumbers → phoneNumbers array
  * emailAddresses → emailAddresses array
* **Transition:** Go to AddToList

### 5. State: AddToList

Add fullName (or firstName + lastName) to your UI list component.

* Increment contactIndex by 1
* Return to LoopStart

## Loop Pattern

```
contactIndex = 0

While (contactIndex < contactCount):
    GetContactInfo(contactIndex)
    AddToList(fullName)
    contactIndex++
```

## Common Issues

* **Index Out of Range**: Ensure loop condition is `contactIndex < contactCount` (not <=)
* **Empty Names**: Some contacts may have empty firstName/lastName; use fullName as fallback
* **Large Lists**: For >50 contacts, consider pagination (see UseCase3)
* **Array Access**: phoneNumbers and emailAddresses are arrays; check Length before accessing

## Performance Tip

For large contact lists (100+), use pagination instead of loading all contacts at once to prevent UI freezing.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://assetstore.essentialkit.voxelbusters.com/features/address-book/playmaker/use-cases/use-case-2-display-contact-list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
