---
schema_version: "1"
id: 0909baecf1d36192ecea176faf8df252d6c11fe76f940f8b6f442e0637c629a1
title: RetrieveMscrmRecordsFetchXml()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/microsoft-dynamics-crm/mc-ampscript-reference-microsoft-dynamics-crm-retrieve-records-fetch-xml.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-mscrm/mc-ampscript-reference-microsoft-dynamics-crm-retrieve-records-fetch-xml.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9d197763989cf378563ff9bf1572b944da5489d12e30446b6596503dad5bcfc7
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# RetrieveMscrmRecordsFetchXml()

Returns the attributes specified in a Fetch XML query.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
RetrieveMscrmRecordsFetchXML(fetchXmlQuery)
```

The `RetrieveMscrmRecordsFetchXML()` has one parameter:

- `fetchXmlQuery` (string): Required. A Microsoft Dynamics CRM Fetch XML query.

## Usage

This function uses a Fetch XML query to retrieve the contact IDs, email addresses, first names, and last names of contacts who have a specific subscriber key.

```
Var @FetchXml
Set @FetchXml = concat('<fetch mapping='logical' count='1' version='1.0'> <entity name='contact'> <attribute name='contactid' /> <attribute name='emailaddresstring' /> <attribute name='firstname' /> <attribute name='lastname' /> <filter> <condition attribute='contactid' operator='eq' value='', @SubscriberKey, '' /> </filter> </entity></fetch>')
Set @RowSet_All = RetrieveMscrmRecordsFetchXML(@FetchXML)

If Rowcount(@RowSet_All) >= 1 then
    Set @RowSet = Row(@RowSet_All, 1)
    Set @contactid = Field(@Rowset,'contactid', 0)
    Set @emailaddresstring = Field(@Rowset,'emailaddresstring', 0)
    Set @firstname = Field(@Rowset,'firstname', 0)
    Set @lastname = Field(@Rowset,'lastname', 0)
EndIf
```

## See Also

- [Use FetchXML to construct a query](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/use-fetchxml-construct-query) in the Microsoft Developer Documentation
