# 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.
