Create a reminder task for a user when an opportunity is inserted.

1 minute read time.

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();

  • Hi Jeff, I understand that the scenario is create reminder task when opportunity is inserted. Would you mind to point me out where should I insert the code? Thanks for sharing

  • Ralph

    It needs to go into the Post Insert event function

    function PostInsertRecord()

    {

    // Handle post insert record actions here

    }

  • Hi Jeff,

    I can't edit my initial post so, just an update. I had a rogue set value field in the workflow that hadn't refreshed back to display for amendment after a change so the value was coming through with the set value field name instead of a value. Error fixed.

    Just one more question, is it possible to set the date fields in the communication so that the communication appears in the calendar with a date it is to be done etc.? I have managed to set it in the sql table it seems but it does not appear in the screen for the date values and therefore isn't available to the calendar to filter through to the right diary date and time.

    Any thoughts here?

    Thanks Jeff.

    Regards,

    Penny

  • Hello Jeff,

    The above table level script I have found works in versions prior to 2017 and 2018 and now, I am seeing unexpected events occurring with the intOppoUserID variable inserted to the OpportunityProgress table. The script has not been altered at all as I am testing it first.

    Is there a major change in the table level scripts with the new versions and PostInsertRecord?

    The dates are not behaving the way I would like either.

    Any updates to entering a new task using table level scripts Jeff?

    Cheers.

    Penny