Using PostInsertRecord in a table-level script

You can include the record ID generated by the InsertRecord function in the PostInsertRecord function of the same script. This example uses the PostInsertRecord function in a table-level script to send a communication suggesting a follow-up call to the company account manager when a new case is created.

Use PostInsertRecord to insert or update other records using the ID of the record that has just been inserted. You can't update the current record in the PostInsertRecord function as it's already been saved. You can read values from the Values collection, however any changes to the Values collection won't take effect.

  1. Open your table-level script.
    For more information on how to create a table-level script, see Creating a script.
  2. Enter the following script in Table Script within the function PostInsertRecord section.
    Copy
    function PostInsertRecord() 
    {
        intid = CRM.getContextInfo('company','comp_companyid'); 
        var d=new Date(); 
        var CmLiRec,CommRec; 
        var CompRec=CRM.FindRecord("Company","Comp_CompanyId="+intid); 
        if (CompRec.Comp_PrimaryUserId +""!="undefined"
        { 
        CommRec=CRM.CreateRecord("Communication"); 
        CommRec.Comm_Action='PhoneOut'
        CommRec.Comm_Type='Task'
        CommRec.Comm_Status='Pending'
        CommRec.Comm_note="Make follow up call to client to find out 
        details of case and assure action"; 
        CommRec.Comm_Priority='Normal'
        CommRec.SaveChanges(); 
        CmLiRec=CRM.CreateRecord("Comm_Link"); 
        CmLiRec.CmLi_Comm_CommunicationId=CommRec.Comm_CommunicationId; 
        CmLiRec.Cmli_Comm_CompanyId=intid; 
        CmLiRec.Cmli_Comm_NotifyTime=d.getVarDate(); 
        CmLiRec.Cmli_Comm_UserId=CompRec.Comp_PrimaryUserId; 
        CmLiRec.SaveChanges();
        }
    }
  3. Click Save.

Create a new case and note the user to whom it's assigned. Log on as that user and view the created task in the calendar.