I have a custom object that has lookup to Contact. I need to create button on the custom object "Pipeine__c" that when I click it creates a NEW Task and it copies the contact name from the "Pipeline__C" object to the New Task and redirect to New Task page layout. Here is my JavaScript code so far:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
try{
var taskToCreate = new sforce.SObject("Task");
taskToCreate.OwnerId = "{!$User.Id}";
taskToCreate.Status = "Not Started";
taskToCreate.Priority = "Normal";
var 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
);