Programmatically create new task

  • Hello, I just wanted, from my ASP page, to create a new task for current company, changing subject, start and finish time, task type and so on. After adding a custom record in the ASP page, wanted to create a related task. 

    Thanks

    Francisco

     

  • Below is a code snippet that shows how to create a task using the COM API in javascript.  You have to create both a communication record and a comm_link record.

    
    /////////create communication/////////////////
    var myDate = new Date();
    var recCommunication = CRM.CreateRecord("communication");
    recCommunication.comm_action = "LetterOut";
    recCommunication.comm_type = "Task";
    recCommunication.comm_channelid = recUser.user_primarychannelid;
    recCommunication.comm_status = "Complete";
    recCommunication.comm_priority = "Normal";
    recCommunication.comm_datetime = myDate.getVarDate();
    recCommunication.comm_note = "details go here"
    recCommunication.SaveChanges();
    
    var recCommLink = CRM.CreateRecord("comm_link");
    recCommLink.cmli_comm_userid = recUser.user_userid;
    recCommLink.cmli_comm_communicationid = recCommunication.comm_communicationid;
    recCommLink.cmli_comm_personid = recCompany.comp_primarypersonid;
    recCommLink.cmli_comm_companyid = recCompany.comp_companyid;
    recCommLink.SaveChanges();
    
     


  • Worked like a charm with some mods, note the recUser and recCompany entities are not available on my page, but values were handy from the 'record' object. Let me know if you want full script posted.

  • Can I ask you in general, Jeff in particular, how to accomplish this from a tablescript? The idea is review if a checkbox has been ticked on company creation or modification, so if the check is true I'll have to create a periodic task each quarter, with no end date. Any sample?