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
pasmithpasmith 

trying to create task with fields populated on a lead record

I want users of the system to be able to push a button on a Lead record to create and associate a task with fields already populated. I am able to create the button and place it where it needs to be. My problem is with the onclick javascript code. When the button is pressed with the code below, nothing happens. Please let me know how I can accomplish this.

Here is my code:

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

var task = new sforce.SObject("Task");
task.RecordType = "Custom Record Type";
task.Status = "Not Started";
task.Subject = "CustomLabel: " + "{!Lead.Company}" + "{!Lead.LastName}";
task.WhoId= "{!Lead.Id}";

var result = sforce.connection.create([task]);


pasmithpasmith
The error code I get seems to suggest I cannt set a field. In my case I am trying to create an instance of a custom type. My code above creates a Task object and tries to set the RecordType field. How do I directly create an instance of the custom taks so I don't have to set the RecordType field.?
Ron HessRon Hess
Can you add an alert() to capture the error?

something ilke
 alert(saveResult.toString())
ScrapsScraps

Record type needs to be RecordTypeId i.e.

 

 

var t=new sforce.SObject("Task"); t.RecordTypeId = "012200000008o5z"; t.Status = "Not Started"; t.Subject = "Subject Text"; t.WhatId= "{!Account.Id}"; var result = sforce.connection.create([t]);