You need to sign in to do that
Don't have an account?

Java Script is not working for Button click ?
I have created Detailed abutton and placed on the Task Record. The button should function like when we click the button a New opportunity page will opened and carry the data from Task to the Opportunity and need to display on Opportunity fields. Below javascript created. But it giving error like that 'Task.WhoId' is not exist like that. Please anyone correct bthis.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var OpportunityCreate= new sforce.SObject("Opportunity");
OpportunityCreate.Contact_Name__c = '{!Task.WhoId}';
var result = sforce.connection.create([OpportunityToCreate]);
if (result[0].success == 'true')
var newURL = '/' + result[0].id + '/e';
window.top.location = newURL;
}
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var OpportunityCreate= new sforce.SObject("Opportunity");
OpportunityCreate.Contact_Name__c = '{!Task.WhoId}';
var result = sforce.connection.create([OpportunityToCreate]);
if (result[0].success == 'true')
var newURL = '/' + result[0].id + '/e';
window.top.location = newURL;
}
check your this line : var result = sforce.connection.create([OpportunityToCreate]);
and try
i think it should be like this :var result = sforce.connection.create([OpportunityCreate]);
If your problem solved then please mark it as best answer so that it appear as a solved qusestion.
Thanks
Rishav
Use following code and pass the required field value based on your organizations.....
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var OpportunityCreate = new sforce.SObject("Opportunity");
OpportunityCreate.Name = '{!Task.Status}'+' - '+'Opportunity by Task';
OpportunityCreate.CloseDate = '2016-10-26Z';
OpportunityCreate.StageName = 'Prosecting';
OpportunityCreate.ForecastCategoryName = 'Pipeline';
var result = sforce.connection.create([OpportunityCreate]);
window.location.href = '/'+result[0].id;
Thanks & Regards,
Ranjeet Singh.