Peek Under the Hood
A picture is worth a thousand words, but to developers a code sample is clearer than both. In this simple C# example we'll show how Microsoft Dynamics CRM could take an incoming fax and convert it to a Follow-up Task with a due date a week after it was received.
using System;
using Microsoft.Crm.Sdk.Utility;
using CrmSdk;
namespace Microsoft.Crm.Sdk.HowTo
{
/// <summary>
/// This sample shows how to convert a fax into a task.
/// </summary>
public class ConvertFaxToTask
{
static void Main(string[] args)
{
ConvertFaxToTask.Run("http://localhost:5555", "CRM_SDK");
}
public static bool Run(string crmServerUrl, string orgName)
{
#region Setup Data Required for this Sample
bool success = false;
#endregion
try
{
// Set up the CRM Service.
CrmService service = CrmServiceUtility.GetCrmService
(crmServerUrl, orgName);
service.PreAuthenticate = true;
// Get the current user.
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);
// Create the fax object.
fax fax = new fax();
// Set the properties of the fax.
fax.subject = "Test Fax";
fax.description = "New Fax";
// Create the party sending and receiving the fax.
activityparty party = new activityparty();
// Set the properties of Activityparty.
party.partyid = new Lookup();
party.partyid.type = EntityName.systemuser.ToString();
party.partyid.Value = user.UserId;
// The party sends and receives the fax.
fax.from = new activityparty[] { party };
fax.to = new activityparty[] { party };
// Create the fax.
Guid createdFaxId = service.Create(fax);
// Retrieve the created fax.
fax newFax = (fax)service.Retrieve(EntityName.fax.ToString(),
createdFaxId, new AllColumns());
// Create the task object.
task task = new task();
// Set the properties of the task.
task.subject = "Follow Up: " + newFax.subject;
// Due date of the task.
task.scheduledend = new CrmDateTime();
// Get the date that the fax was received.
DateTime endDate = DateTime.Parse(newFax.createdon.date);
// Add one week to get the date that the task is due.
endDate = endDate.AddDays(7);
// Set the due date of the task.
task.scheduledend.Value = endDate.ToString();
// Create the task.
Guid createdTaskId = service.Create(task);
#region check success
if (createdTaskId != Guid.Empty)
{
success = true;
}
#endregion
#region Remove Data Required for this Sample
service.Delete(EntityName.fax.ToString(), createdFaxId);
service.Delete(EntityName.task.ToString(), createdTaskId);
#endregion
}
catch (System.Web.Services.Protocols.SoapException)
{
// Add your error handling code here.
}
return success;
}
}
}
That's all there is to it. You've just created a useful feature that would take a whole lot of code to implement outside of Microsoft Dynamics CRM. You also don't need to write the code to manage tasks (assign them to other users, delete them, update them, include them in the workflow, and so on), it's all done for you by the underlying Microsoft Dynamics CRM platform.
What Are You Waiting For?
Microsoft Dynamics CRM 4.0 is clearly a solution that CRM developers (and those responsible for CRM initiatives) should seriously investigate. It brings rapid development to CRM so you can get to market faster and at a lower cost. Be sure to download the Dynamics CRM 4.0 SDK to learn all about creating plug-ins, working with custom workflow activities, using the new Web services and data management features, and much more. The code samples, step-by-step learning materials, and detailed reference guide show just how easy it is to integrate your applications with the platform. Those looking for a first hand overview of Microsoft Dynamics CRM 4.0 should plan to attend one of the upcoming Microsoft Dynamics CRM 4.0 Launch Events and Microsoft Dynamics™ Discovery Day Roadshows.
* This article was commissioned by and prepared for Microsoft Corporation. This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.