Users of ExactTarget for Microsoft Dynamics CRM use these AMPscript functions in conjunction with Smart Capture and landing pages to modify records in the Microsoft Dynamics CRM system.
Updates one or more records in a Microsoft Dynamics CRM entity. Also returns the number of records that were successfully updates.
%%[
/* Sample Code - this updates several lead records to have Web as a Lead Source Code in mscrm */
var @records_updated
set @records_updated = updatemscrmrecords('lead', '2E438216-2DEE-DD11-AB3E-005056AD58C4,0A167EEC-6436-DD11-B7BE-000E7F30252C', 'leadsourcecode', '8')
]%%
<p>Count of records updated:</p><br>
%%=v(@records_updated)=%% Retrieves a single record from Microsoft Dynamics CRM and sorts them using the sort field and order provided. Updates records based on Name and Value attributes. If no record is found, one is created using Name and Value attributes. Returns the GUID of the updated or created record.
Creates a single Dynamics CRM record in the target entity. Returns the GUID of the created record.
%%[
/* Sample Code - this creates a new Contact record */
var @contact_guid
set @contact_guid = createmscrmrecord('contact', 3, 'firstname', 'bob', 'lastname', 'testcontact', 'emailaddress1', 'bob@example.com')
]%%
<p>GUID of new Contact:</p><br>
%%=v(@contact_guid)=%% Retireves multiple CRM records. Use fields in the target entity or select fields from related entities by using Many:1 lookup attributes.
You can select the name of the parent account by including parentaccount.id name in the list of fields. You can also filter on Many:1 lookup attributes by using the same nomenclature. To retrieve accounts where the parent account's name is Example.com, include "parentaccountid.name","=","Example.com" in your filters. All values regularly retrieved in Fetch XML queries are returned. If parentaccount.id is one of the fields to be returned, the results will have columns parentaccountid, parentaccountid.name, and parentaccountid.type.
%%[
/* Sample Code - this retrieves all contacts where the first name is John */
var @records_retrieved, @counter, @firstname, @lastname, @id
set @records_retrieved = retrievemscrmrecords('contact', 'contactid,firstname,lastname', 'firstname', '=', 'john')
]%%
<p>Contacts:</p><br><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><br>
%%[next @counter ]%% Takes a correctly formed Fetch XML query and returns the attributes specified in the query.
Returns the logical name and display name of all Microsoft Dynamics CRM entities
%%[ /* Sample code to get a list of all entities in a crm account to a record set */ var @entities_rs set @entities_rs = describemscrmentities() ]%% <p> Here is a list of CRM Entities </p> %%[ var @entity_name, @entity_displayname, @counter for @counter = 1 to rowcount(@entities_rs) do set @entity_name = field(row(@entities_rs,@counter), 'Name') set @entity_displayname = field(row(@entities_rs,@counter), 'DisplayName') ]%% Entity Name: %%=v(@entity_name)=%% <br> Entity Display Name: %%=v(@entity_displayname)=%% <br> <br><br> %%[ next @counter ]%%
Returns the logical name, display name, and type of the Dynamics CRM entity. If the attribute is Boolean, status, a picklist, or a state, the function returns a comma-separated list of option and display values.
S1 The Dynamics CRM entity from which to retrieve attributes
%%[
var @fields_rs
set @fields_rs = describemscrmentityattributes('lead')
]%%
<p> Here is a list of Fields in the Lead Entity </p>
%%[
var @field_name, @field_displayname, @counter, @field_type, @field_required, @field_options
for @counter = 1 to rowcount(@fields_rs) do
set @field_name = field(row(@fields_rs,@counter), 'Name')
set @field_displayname = field(row(@fields_rs,@counter), 'DisplayName')
set @field_type = field(row(@fields_rs,@counter), 'Type')
set @field_required = field(row(@fields_rs,@counter), 'Required')
set @field_options = field(row(@fields_rs,@counter), 'Options')
]%%
Field Name: %%=v(@field_name)=%% <br>
Field Display Name: %%=v(@field_displayname)=%% <br>
Field Type: %%=v(@field_type)=%% <br>
Field Required?: %%=v(@field_required)=%% <br>
Field Options: %%=v(@field_options)=%% <br> <br><br>
%%[ next @counter ]%% Adds the indicated record to the indicated marketing list. No return value.
%%[ /* Adds a lead, contact or account to a marketing list */ var @guid, @list_guid set @guid = '2E438216-2DEE-DD11-AB3E-005056AD58C4' set @list_guid = '0A167EEC-6436-DD11-B7BE-000E7F30252C' AddMscrmListMember(@guid, @list_guid) ]%%
Sets state and status of the indicated record. Provides "-1" as the status value for the state's default status. No return value.
NOTE: Some entities, including Opportunity, require special CRM requests to change their state. This method will not work for those entities.
%%[
/* sample code to change the state of an account to inactive */
SetStateMscrmRecord("00000000-0000-0000-0000-000000000001", "account", "Inactive", "-1")
]%% If the attribute specified can be related to multiple Dynamics CRM entities, you must specify the type of entity the attribute belongs to by adding |lookup (replacing lookup with the entity). For example, the customerid field could be related to an account or contact. If it's related to an account, specify this by adding |account at the end of the attribute.
By including |partyentityname (subsituting your name for the text following the pipe) at the end of a series of fields and values, you can create a record on the party list with those fields and values. Only one record will be created, but any values (except for another party list) can be populated. This attribute is specifically for use with campaign responses, and the party list maps directly to the customer field on a campaign response.
"field,value,field2,value2"|examplepartylist
The above text would create a record on example partylist with two fields (field and field 2) assigned different values (value and value2, respectively).