AMPscript Functions for use with Microsoft Dynamics CRM

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.

UpdateMscrmRecords(S1,S2,S3a,S3b...SNa, SNb)

Updates one or more records in a Microsoft Dynamics CRM entity. Also returns the number of records that were successfully updates.

Arguments

  • S1                The name of the Microsoft Dynamics CRM entity receiving the updated records
  • S2                A comma-separated list of the record GUIDs to update
  • S3a, S3b       Name and Value parts of attribites to update on the target records

Example

%%[

/* 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)=%%

UpsertMscrmRecord(S1,S2,S3,S4,S5a,S5b,S6a,S6b)

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.

Arguments

  • S1                The name of the Dynamics CRM entity for the record to upsert
  • S2                The field used to sort the retrieve results
  • S3                The order used to sort the retrieve results (ASC|DSC)
  • S4                The number of Name/Value pairs of fields used to retrieve
  • S5a, S5b       Name/Value pairs of attributes to filter on the target entity
  • S5a, S5b       Name/Value pairs of attributes to update on the target record

CreateMscrmRecord(S1,S2,S3a,S3b)

Creates a single Dynamics CRM record in the target entity. Returns the GUID of the created record.

Arguments

  • S1             The name of the Dynamics CRM entity for the record to create
  • S2             The number of Name/Value pairs of fields to populate on the created record
  • S3a, S3b    Name/Value pairs of attributes to populate on 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)=%%

RetrieveMscrmRecords(S1,S2,S3a,S3b,S3c)

Retireves multiple CRM records. Use fields in the target entity or select fields from related entities by using Many:1 lookup attributes.

Arguments

  • S1                    The name of the Dynamics CRM entity from which to retrieve records
  • S2                    A comma-separated list of fields to retrieve
  • S3a, S3b, S3c    Field to check value of, operator, and value

Example

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: &nbsp; &nbsp; %%=v(@firstname)=%% </p>

<p>Last: &nbsp; &nbsp; %%=v(@lastname')=%% </p>

<p>Id: &nbsp; &nbsp; %%=v(@id)=%% </p>  <br><br>

%%[next @counter ]%%

RetrieveMscrmRecordsFetchXML(S1)

Takes a correctly formed Fetch XML query and returns the attributes specified in the query.

Arguments

  • S1    Microsoft Dynamics CRM Fetch XML query

DescribeMscrmEntities()

Returns the logical name and display name of all Microsoft Dynamics CRM entities

Example

%%[

/* 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: &nbsp; &nbsp; %%=v(@entity_name)=%% <br>

Entity Display Name: &nbsp; &nbsp; %%=v(@entity_displayname)=%% <br> <br><br>

%%[ next @counter ]%%

 

DescribeMscrmEntityAttributes(S1)

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.

Arguments

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: &nbsp; &nbsp; %%=v(@field_name)=%% <br>

Field Display Name: &nbsp; &nbsp; %%=v(@field_displayname)=%% <br>

Field Type: &nbsp; &nbsp; %%=v(@field_type)=%% <br>

Field Required?: &nbsp; &nbsp; %%=v(@field_required)=%% <br>

Field Options: &nbsp; &nbsp; %%=v(@field_options)=%% <br> <br><br>

%%[ next @counter ]%%

AddMscrmListMember(S1,S2)

Adds the indicated record to the indicated marketing list.  No return value.

Arguments

  • S1    The GUID of the record to add to the marketing list
  • S2    The GUID of the marketing list receiving the marketing list
%%[

/* 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)

]%%

SetStateMscrmRecord(S1,S2,S3,S4)

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.

Arguments

  • S1    The GUID of the record to set the state and status for
  • S2    The Dynamics CRM entity name of the record
  • S3    The state to set, such as "Active" or "Inactive"
  • S4    The status to set, such as "1" or "0"
%%[

/* sample code to change the state of an account to inactive */

SetStateMscrmRecord("00000000-0000-0000-0000-000000000001", "account", "Inactive", "-1")  

]%%

Special Attribute Types

Lookup

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.

Party List

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.

Example

"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).

 


Enter the digits 26555 backwards:
   
 

 

 

Tag page
You must login to post a comment.