---
schema_version: "1"
id: fe94799ae1c57b1ce5f1f2c2b411beb64c94723e19107a893f4f977bc77a297f
title: UpsertMscrmRecord()
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-upsert-record.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-mscrm/mc-ampscript-reference-microsoft-dynamics-crm-upsert-record.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8f0a8bc100f0df18c43c60e0318adbdd72a85f4ebfddf39e040ac9baba874cf9
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# UpsertMscrmRecord()

Upserts a Microsoft Dynamics CRM record.

This function retrieves a single record from Microsoft Dynamics CRM, using the name and value parameters to filter the results. It then sorts the results. If the function finds a matching record, it updates the record with the provided name and value. If the function doesn’t find a record, it creates one using the provided name and value.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
UpsertMscrmRecord(entityName,
                  sortField, sortType,
                  numPairsForFilter, filterAttributeName, filterAttributeValue,
                  numPairsForUpdate, updateAttributeName, updateAttributeValue)
```

The `UpsertMscrmRecord()` function has nine parameters:

- `entityName` (string): Required. The name of the Microsoft Dynamics CRM entity to upsert.
- `sortField` (string): Required. The field to sort the retrieve results on.
- `sortType` (string): Required. The order to use to sort the retrieve results. Accepted values: `ASC` (ascending) or `DESC` (descending).
- `numPairsForRetrieve` (string): Required. The number of name-value pairs used to retrieve results.
- `filterAttributeName` (string): Required. The name of the attribute to filter the target entity by.
- `filterAttributeValue` (string): Required. The value of the attribute to filter the target entity by.
- `numPairsForUpdate` (string): Required. The number of name-value pairs used to update records.
- `updateAttributeName` (string): Required. The name of the attribute to update in the target entity.
- `updateAttributeValue` (string): Required. The value of the attribute to update in the target entity.

## Usage

This example first checks to see if an account exists where the name equals “MarketingCloud”. If there is, it finds the one created most recently and sets the address1_city of that record to “Indianapolis.” If there isn’t, it creates a record where the name is “MarketingCloud” and the address1_city is “Indianapolis.”

```
%%[
  UpsertMscrmRecord("account",
                    "createdon","DESC",
                    1,"name","MarketingCloud",
                    1,"address1_city","Indianapolis")
]%%
```

The function returns the GUID of the updated or created record.
