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.AddUser(CurrentUser.UserId); newAppointment.SetField("comm_action", "Meeting"); newAppointment.SetField("comm_note", "This is an example task"); newAppointment.SaveChanges();
Create a Task
CommunicationEntity newTask = CreateTask(); newTask.AddUser(CurrentUser.UserId); newTask.SetField("comm_action", "ToDo"); newTask.SetField("comm_note", "This is an example task"); newTask.SaveChanges();
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.AddUser(CurrentUser.UserId); newTask.SetField("comm_channelid",CurrentUser.TeamId); newTask.SetField("comm_action", "ToDo"); newTask.SetField("comm_note", "This is an example task"); newTask.SetField("comm_subject", "This is an example task"); newTask.SaveChanges(); 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); commlinkRecord.SaveChanges(); } } }
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.