# RetrieveMscrmRecords()

Retrieves data from Microsoft Dynamics CRM entities.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
RetrieveMscrmRecords(entityName, fieldsToRetrieve,
                     queryFieldName, queryFieldOperator, queryFieldValue)
```

The `RetrieveMscrmRecords()` function has five parameters:

- `entityName` (string): Required. The name of the Microsoft Dynamics CRM entity to retrieve records from.
- `fieldsToRetrieve` (string): Required. A comma-separated list of fields to retrieve.
- `queryFieldName` (string): Required. The name of the field to filter on.
- `queryFieldOperator` (string): Required. The operator to use for the filter.
- `queryFieldValue` (string): Required. The value to filter on.

## Usage

This example retrieves the contact ID, first name, and last name for all contacts where the last name is Santos.

```
%%[
  Var @records_retrieved, @counter, @firstname, @lastname, @id
  Set @records_retrieved = RetrieveMscrmRecords("contact", "contactid,firstname,lastname",
                                                "lastname", "=", "Santos")
]%%

<p>Contacts:</p>
<br />

%%[
  For @counter = 1 to RowCount(@records_retrieved) do
  Set @firstname = Field(Row(@records_retrieved,@counter),'firstname')
  Set @lastname = Field(Row(@records_retrieved,@counter),'lastname')
  Set @id = Field(Row(@records_retrieved,@counter),'contactid')
]%%

<p>First: %%=v(@firstname)=%%</p>
<p>Last: %%=v(@lastname)=%%</p>
<p>Id: %%=v(@id)=%%</p>
<br />

%%[ Next @counter ]%%
```
