This sample code shows how to convert a fax to a task. The code first creates an incoming Fax activity, and then converts it to a Follow-up Task with a due date a week after it was received.
1: //# Convert a Fax to a Task
2: using System;
3: using Microsoft.Crm.Sdk.Utility;
4: 5: namespace Microsoft.Crm.Sdk.HowTo
6: {7: // Microsoft Dynamics CRM namespaces.
8: using CrmSdk;
9: 10: /// <summary>
11: /// This sample shows how to convert a fax into a task.
12: /// </summary>
13: public class ConvertFaxToTask
14: {15: static void Main(string[] args)
16: {17: // TODO: Change the server URL and organization to match your Microsoft Dynamics CRM server and Microsoft Dynamics CRM organization.
18: ConvertFaxToTask.Run("http://localhost:5555", "CRM_Organization");
19: } 20: 21: public static bool Run(string crmServerUrl, string orgName)
22: {23: #region Setup Data Required for this sample.
24: 25: bool success = false;
26: 27: #endregion
28: 29: try
30: {31: // Set up the CRM service.
32: CrmService service = CrmServiceUtility.GetCrmService(crmServerUrl, orgName);33: service.PreAuthenticate = true;
34: 35: // Get the current user.
36: WhoAmIRequest userRequest = new WhoAmIRequest();
37: WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest); 38: 39: // Create the fax object.
40: fax fax = new fax();
41: 42: // Set the properties of the fax.
43: fax.subject = "Test Fax";
44: fax.description = "New Fax";
45: 46: // Create the party sending and receiving the fax.
47: activityparty party = new activityparty();
48: 49: // Set the properties of the activity party.
50: party.partyid = new Lookup();
51: party.partyid.type = EntityName.systemuser.ToString(); 52: party.partyid.Value = user.UserId; 53: 54: // The party sends and receives the fax.
55: fax.from = new activityparty[] { party };
56: fax.to = new activityparty[] { party };
57: 58: // Create the fax.
59: Guid createdFaxId = service.Create(fax); 60: 61: // Retrieve the created fax.
62: // Be aware that using AllColumns may adversely affect
63: // performance and cause unwanted cascading in subsequent
64: // updates. A best practice is to retrieve the least amount of
65: // data required.
66: fax newFax = (fax)service.Retrieve(EntityName.fax.ToString(), createdFaxId, new AllColumns());
67: 68: // Create the task object.
69: task task = new task();
70: 71: // Set the properties of the task.
72: task.subject = "Follow Up: " + newFax.subject;
73: 74: // Set the due date of the task.
75: task.scheduledend = new CrmDateTime();
76: 77: // Get the date that the fax was received.
78: CrmDateTime endDate = newFax.createdon; 79: 80: // Set the due date of the task to one week later.
81: task.scheduledend.Value = endDate.UniversalTime.AddDays(7).ToString(); 82: 83: // Create the task.
84: Guid createdTaskId = service.Create(task); 85: 86: #region check success
87: 88: if (createdTaskId != Guid.Empty)
89: {90: success = true;
91: } 92: 93: #endregion
94: 95: #region Remove Data Required for this Sample
96: 97: service.Delete(EntityName.fax.ToString(), createdFaxId); 98: service.Delete(EntityName.task.ToString(), createdTaskId); 99: 100: #endregion
101: }102: catch (System.Web.Services.Protocols.SoapException)
103: {104: // Add your error handling code here.
105: } 106: 107: return success;
108: } 109: } 110: }
No comments:
Post a Comment