You need to sign in to do that
Don't have an account?
Kate Porter 3
Onclick Javascript to set record type for new task
I can create a new task from a button and set all the fields I want except the record type. Can anyone help?
I tried myTask.RecordType = "Support Type"; and also RecordTypeID. I either get an error message or no task created.
This code works:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var myTask = new sforce.SObject("Task");
myTask.WhatId= "{!Case.Id}";
myTask.Subject = "{!Case.Account} - {!Case.Reason}";
myTask.status = "Not Started";
myTask.Activity_Business_Type__c = "Existing Business";
myTask.Type = "Product Support Task";
myTask.ActivityDate = "{!SUBSTITUTE(TEXT(TODAY()+3), "/", "-")}";
sforce.connection.create([myTask]);
window.location.reload();
I tried myTask.RecordType = "Support Type"; and also RecordTypeID. I either get an error message or no task created.
This code works:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var myTask = new sforce.SObject("Task");
myTask.WhatId= "{!Case.Id}";
myTask.Subject = "{!Case.Account} - {!Case.Reason}";
myTask.status = "Not Started";
myTask.Activity_Business_Type__c = "Existing Business";
myTask.Type = "Product Support Task";
myTask.ActivityDate = "{!SUBSTITUTE(TEXT(TODAY()+3), "/", "-")}";
sforce.connection.create([myTask]);
window.location.reload();
Add below code in your existing code.
RecordType rt = [select Id from RecordType where Name = 'XXX ' and SobjectType = 'Task' limit 1];
Then assing myTask.RecordTypeId = rt.Id
Below is my working code.