Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

InstantiateTemplate Message

CRM 1.2
banner art

Creates an e-mail message from a template.

The relevant classes are specified in the following table.

Type Class
Request InstantiateTemplateRequest
Response InstantiateTemplateResponse
Entity template

Remarks

To perform this action, the caller must access rights on the template entity instance. For a list of required privileges, see InstantiateTemplate Privileges.

Example

[C#]
// Set up the CRM Service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create a template instantiation request.
InstantiateTemplateRequest instTemplate = 
    new InstantiateTemplateRequest();

// The email template to use.
instTemplate.TemplateId = 
    new Guid("9AF74EF9-A04C-DA11-A0C5-000D9DD8CDAC");

// The object that this email is regarding.
instTemplate.ObjectId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");
instTemplate.ObjectType = EntityName.account.ToString();

//Uncomment this next line to return dynamic entities.
//instTemplate.ReturnDynamicEntities = true;

// Execute the request to create an email message from the template.
InstantiateTemplateResponse instTemplateResponse = 
   (InstantiateTemplateResponse)service.Execute(instTemplate);

// Serialize the email message to XML and save to a file.
XmlSerializer serializer = new XmlSerializer(typeof(InstantiateTemplateResponse));
string filename = "email-message.xml";
StreamWriter writer = new StreamWriter(filename);                      
serializer.Serialize(writer, instTemplateResponse);
writer.Close();
[Visual Basic .NET]
' Set up the CRM Service.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create a template instantiation request.
Dim instTemplate As InstantiateTemplateRequest = 
    New InstantiateTemplateRequest

' The email template to use.
instTemplate.TemplateId = 
    new Guid("9AF74EF9-A04C-DA11-A0C5-000D9DD8CDAC");

' The object that this email is regarding.
instTemplate.ObjectId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");
instTemplate.ObjectType = EntityName.account.ToString

' Uncomment this next line to return dynamic entities.
'instTemplate.ReturnDynamicEntities = true;

' Execute the request to create an email message from the template.
Dim instTemplateResponse As InstantiateTemplateResponse =
    CType(service.Execute(instTemplate), InstantiateTemplateResponse)

' Serialize the email message to XML and save to a file.
Dim serializer As XmlSerializer = 
    New XmlSerializer(GetType(InstantiateTemplateResponse))
Dim filename As String = "email-message.xml"
Dim writer As StreamWriter = New StreamWriter(filename)
serializer.Serialize(writer, instTemplateResponse)
writer.Close()

Related Topics

CrmService Messages


© 2007 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.