0

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

2 Answers 2

0

Be thinking about which field on Task you want to populate with the related Contact. I arbitrarily chose to put the Contact into the new Task's Subject field.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

var newtask= new sforce.SObject("Task");
newtask.Subject = "{!Pipeline__c.ContactLookupField__c}";
var result = sforce.connection.create([newtask]);

window.location = "/" + result[0].id + "/e";

Add error handling, etc. and expand functionality to suit your purposes.

0

Can we Instead of creating a new task just click the JS button and redirect from Pipeline__c page layout to the "New Task" page layout and have the user enter the subject and the rest of info? However copy the Contact name from Pipline__c.Financial_Advisors__c to the New Task.Name__c obj.

1
  • window.location = "/00T" + "/e?tsk5={!Pipeline__c.ContactLookupField__c}";
    – krigi
    Commented Apr 3, 2015 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .