Creating Appointments and Tasks in the .NET API

1 minute read time.

It is very easy to work with communications in the .NET API.

Below are the basic code sample to show how to create either an appointment or a new task.

Note: The CreateAppointment() and CreateTask() require you to reference both the WebObject and Data namespaces.

Create an Appointment

CommunicationEntity newAppointment = CreateAppointment();
newAppointment.SetField("comm_action", "Meeting");
newAppointment.SetField("comm_note", "This is an example task");

Create a Task

CommunicationEntity newTask = CreateTask();
newTask.SetField("comm_action", "ToDo");
newTask.SetField("comm_note", "This is an example task");

A link to a parental cases or opportunity is easy as these are just fields in the main communication table ad can be added using

newTask.SetField("comm_opportunity",int.Parse(GetContextInfo("opportunity", "oppo_opportunityid"));

The detail of the user is added to the comm_link table.

BUT links to the company and person actual belong to the communication link table. If you want to link the newly create Appointment or Task to a company or person then you code will need to update the comm_link record that is implicitly created.

An example is show below

using Sage.CRM.WebObject;
using Sage.CRM.Data;
namespace Create_Task
public class MyCustomPage : Web
public override void BuildContents()
CommunicationEntity newTask = CreateTask();
newTask.SetField("comm_action", "ToDo");
newTask.SetField("comm_note", "This is an example task");
newTask.SetField("comm_subject", "This is an example task");
int companyID = int.Parse(GetContextInfo("company", "comp_companyid"));
Record commlinkRecord = FindRecord("comm_link", "CmLi_Comm_CommunicationId="+newTask.RecordId);//parameters as string values
commlinkRecord.SetField("cmli_comm_companyid", companyID);

Once the newTask.SaveChanges method is called the unique ID of the communication record can be found and it can be used to retrieve the corresponding comm_link record. This can then be updated.

  • Hi Jeff,

    Ignore my last comment, it was caused by me trying to set the date field values. However, I have a new problem. When I look at the communication, the communication date is set to midnight today i.e. 2014-10-08 00:00:00. I have tried setting the Comm_DateTime field but it does not seam to update to correct time.

  • Hi Jeff,

    I'm trying to create a task and link it to a Person and Company account, the issue I have is when I try to save the task, I get an error "[SafeCall Exception]: UnexpectedEvent":

    CommunicationEntity MyCommunication = CreateTask();


    MyCommunication.SetField("Comm_ChannelId", CurrentUser.TeamId);

    MyCommunication.SetField("Comm_Type", "Email");

    MyCommunication.SetField("Comm_Action", "EmailOut");

    MyCommunication.SetField("Comm_Status", "Complete");

    MyCommunication.SetField("Comm_Priority", "Normal");

    MyCommunication.SetField("Comm_Email", MyMailBody);

    MyCommunication.SetField("Comm_DateTime", DateTime.Now);

    MyCommunication.SetField("Comm_CreateDate", DateTime.Now);

    MyCommunication.SetField("Comm_UpdatedDate", DateTime.Now);

    MyCommunication.SetField("Comm_TimeStamp", DateTime.Now);

    MyCommunication.SetField("Comm_SecTerr", (int)CurrentUser.TerritoryId);

    MyCommunication.SetField("Comm_From", UserName + " ");

    MyCommunication.SetField("Comm_To", Receipient.ToString());

    MyCommunication.SetField("Comm_CC", UserName + " ");

    MyCommunication.SetField("Comm_IsHTML", "Y");

    MyCommunication.SetField("Comm_Subject", MyMailSubject);


    //error occurs on save...

    //Need to create a Link...

    Record recCommLink = FindRecord("comm_link", "CmLi_Comm_CommunicationId=" + MyCommunication.RecordId);

    recCommLink.SetField("CmLi_Comm_PersonId", strPersonID);

    recCommLink.SetField("CmLi_Comm_CompanyId", strCompID);

    recCommLink.SetField("CmLi_Comm_AccountId", strCompID);