Workflow is very powerful but one of the limitations is that Follow Up Actions, such as 'Create Task' or 'Create Appointment' can not be invoked on Primary Rules.

This means that if a business rule states that a task or an appointment must be created as an Opportunity or Case is inserted then this Communication must be inserted using another mechanism.

If we need to create a communication as the workflow primary rule saves the new record then we can uses a Post Insert event function of a Table level script on the opportunity (or other) entity.

We will have to:

  • Get the newly create opportunity details
  • Create a new communication record
  • Add the details to the communication
  • Save the communication
  • Create a communication link record
  • Add the details to the communication link record
  • Save the comm_link record

Below is some sample code.

var newOppoRecord = CRM.FindRecord("opportunity",WhereClause);
var intOppoID = newOppoRecord.oppo_opportunityid;
var intOppoUserID = newOppoRecord.oppo_assigneduserid;
var intPersID = newOppoRecord.oppo_primarypersonid;
var intCompID = newOppoRecord.oppo_primarycompanyid;
var PersRecord = CRM.FindRecord("person","pers_personid="+intPersID);
var CompRecord = CRM.FindRecord("company","comp_companyid="+intCompID);
var intChannelID = CRM.GetContextInfo('user','user_primarychannelid');

var strMsg ="";
strMsg = "Please call ";
strMsg += PersRecord.pers_firstname +" ";
strMsg += PersRecord.pers_lastname+" of ";
strMsg += CompRecord.comp_name+ " regarding ";
strMsg + =newOppoRecord.oppo_description;

var CommRecord = CRM.CreateRecord("Communication");
CommRecord.Comm_ChannelId = intChannelID;
CommRecord.Comm_Type = 'Task';
CommRecord.Comm_Action = 'ToDo';
CommRecord.Comm_Status = 'Pending';
CommRecord.Comm_Priority = 'Normal';
CommRecord.Comm_Note = strMsg;
CommRecord.Comm_Description = strMsg;
CommRecord.comm_opportunityid = intOppoID;
CommRecord.SaveChanges();

var intCommID = CommRecord.comm_communicationid;
var CmLiRecord = CRM.CreateRecord('comm_link');
CmLiRecord.CmLi_Comm_UserId = intOppoUserID; CmLiRecord.CmLi_Comm_CommunicationId = intCommID;
CmLiRecord.CmLi_Comm_PersonId = intPersID;
CmLiRecord.CmLi_Comm_CompanyId = intCompID;
CmLiRecord.SaveChanges();