function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MicheTMicheT 

Custom Button to create a "Task"

I am hoping this is possible. I need to create a Task-like layout to create Services. I would need to customize the fields but I need it to be similar to creating a New Task. The goal is to be able to tie a New Service to an Opportunity. In order to that I want to also create a button on the opportunity layout that pops up and allows user to create a New Service. How to I go about achieving this?
Navin SoniNavin Soni
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

try{
    var taskToCreate = new sforce.SObject("Task");

    taskToCreate.OwnerId = "{!$User.Id}";
    taskToCreate.WhoId = "{!Lead.Id}";
    taskToCreate.Subject = "Outbound Call";
    taskToCreate.ActivityDate = new Date();

    taskToCreate.Priority = "Normal";
    taskToCreate.Status = "Completed";

    taskToCreate.CallType__c = "Left Voicemail";
    taskToCreate.Short_Call_Notes__c = "Left Voice Mail";

    result = sforce.connection.create([taskToCreate]);

    if(result[0].success == "true"){
        location.reload();
    }
    else{
        alert(
            "An Error has Occurred. Error: \r\n" +
            result[0].errors.message
        );
    }
}
catch(e){
    alert("An Un-expected Error has Occurred. Error: \r\n" +e);
}